I'm uncertain of the answer; there seems to be some uncertainty involved in the mechanism, as if there were some kind of principle involved ;-)
I'll never get quantum mechanics, but that's the nature of QM; it simply doesn't work the same way we think the "real world" works. I think the challenge question to this question is "Can a photon even have an exact energy to begin with?"
We have to let go of our own feel for the physical world when we want to learn about how to explain quantum mechanical phenomena.
The only thing you know about the photon is the general conditions under which it arose. You can use a light bulb and a grating, or a narrow spectrum laser, but those only tell you some window in wavelength $\Delta \lambda$ or frequency $\Delta f$.
The energy spread of a group of photons coming out of those devices associated with those spreads is
$$\Delta E \approx \frac{\Delta \lambda}{\lambda}E \approx \frac{\Delta f}{f}E$$
We can calculate a very precise value for the energies of the initial and final states, but for a single atom do those states have precise energies?
Well the ground state of an atom at rest, or at least at very very cold temperature (e.g. laser cooled and trapped), the state where no other transitions are possible or very likely can be pretty well defined, but that upper state is not.
The upper state will have a lifetime, it will last a while and then decay again. We don't know when. Quantum mechanics tells us that if it has a finite lifetime, then it will also have a finite spread in frequencies. The given excited state in a single given atom will have a spread in energies where it can be excited, and the width of that energy $\Delta E$ is related to the width of time that that state will exist before decaying $\Delta t$ by
$$\Delta E \Delta t = \frac{ħ}{2}$$
As @PeterErwin points out this all falls under the uncertainty principle.
Now as @PeterErwin also points out that atom might not be in a near zero velocity, super cool laser cooled trap, but bouncing around in a gas somewhere. That means it will have some uncertainty in speed and direction. Until the transition happens, we don't know which atom it will be, or how fast or which way it will be moving.
So Doppler broadening of the photon due to spread in velocity will contribute to $\Delta E$ as well.
And what's worse is that when atoms collide they screw up each other's quantum states, both by affecting each other's wave functions temporarily (I don't know the name of this effect) and more importantly by shortening the lifetime of the excited state; if you kick it, it just might decay sooner by emitting a photon or by transferring energy to the other atom. That decreases $\Delta t$ and therefore increases $\Delta E$, and is called collisional broadening or pressure broadening.
I guess that first one I didn't know the name of could be called quasi-static pressure broadening?
Basically, nothing is certain in QM; there is no such concept as a precise anything when you want to talk about a single transition event by a single atom. It's all fuzzy, unclear and uncertain. If you want precise, you measure many, many, many times and build up some average.
That's all we've got up here in the macro world, statistical averages of many many many measurements.