The speed of light decreases when it travels from an optically rarer medium to a denser medium, similarly it increases back when it travels from rarer medium to a denser medium. The speed of light in glass is 2 x 10^8 m/s while in air is 3 x 10^8 m/s, from where does a photon get energy to speed up by 10^8 m/s if it travels from glass to air.
The photons aren't even slowing down when they enter a medium. The photons keep meeting atoms in the path and get reflected internally. This increases the total distance that s photon needs to travel. This in turn is what causes the photons to appear to have slowed down.
There is no question of photons requiring energy to speed up when they leave the medium. Moreover, photons must always travel at the speed of light. This is a requirement for every massless particle.