What is the reason behind electron transition in the flame test
The electron releases its energy because it can. It happens because it has a non-zero probability to do so. If it would never happen it would have zero probability.

Whether the electron just got excited prior to emitting some light does not matter. Particles do not have a memory. Instead such processes simply happen based on whether the requirements are met (e.q. absorbing energy is only possible if energy is available) and on probabilistic rules (quantum mechanics).

Consider some particles in thermal equilibrium: Even the though the temperature does not change on a macroscopic level, the particles still constantly exchange heat with each other. This is called dynamic equilibrium. 

The difference to the flame test is, that the particles exchange energy not only by heat, but by light as well.

Exchange of heat is basically a collision of two atoms, so this is a 2-particle process: its rate dependents on the likelihood of those 2 particles "hitting" each other.

Emission of light is a 1-particle process: it can just happen spontaneously. However, absorbing light is a 2-particle process: a photon needs to intercept an atom in order for the atom to absorb its energy.

Heat is the source of energy, and it allows for redistribution between all particles. But for the light, the emission happens much more often than absorption, because 1-particle processes are much more likely to happen than 2-particle processes. Therefore we see the overall emission of light until the heat source is gone.