You are asking about when a electron transitions from a higher energy level to a lower energy level so I will assume you are asking about relaxation. There are other type of transitions, like the Auger effect.
Now when a atom/electron relaxes, it moves from a higher energy level to a lower energy level as per QM, as you state, and releases a photon.
You are asking why this transition releases a massless gauge boson.
Now the photon is an elementary particle, part of the SM, massless, pointlike. Photons always travel at speed c in vacuum, when measured locally.
You are asking why this gauge boson is massless.
There are two ways to look at this:
- gauge invariance, if you want to describe a theory with a zero mass vector and relativity, you have to have gauge invariance. And the photon is massless because it is the mediator of the EM force which is long range. It is because of the unbroken U(1) gauge invariance of the EM force.
Though, the gauge fields may become massive via Higgs (W,Z bosons). But that is a short range force.
Why can't gauge bosons have mass?
How does gauge invariance prevent the photon from acquiring a mass?
- As per SR, anything that travels at the speed of light, cannot have rest mass. This is because it would cost an infinite amount of energy to speed up a massive particle to speed c.
https://en.wikipedia.org/wiki/Photon
https://en.wikipedia.org/wiki/Special_relativity