Fundamental principles for calculating charged defect ionization energies in ultrathin two-dimensional materials