The gain and the loss are not equal. As an analogy, consider e.g. a satellite orbiting the earth. If the zero of PE is taken at infinite distance, then PE = -2KE, so if the satellite moves to a higher orbit it gains twice as much PE as it loses KE. Electrons in an atom are more complicated, but the same principle applies.