Quantum mechanics dictates which energy levels are possible for a given system. If an atom is in its ground state, it will stay there until it is excited by external forces. An electron in an excited state will radiate a photon to return to a lower energy level because it must conserve energy. This occurs only when the energy of the photon exactly matches the energy difference between the two different levels. Spontaneous emission occurs naturally when there is external perturbation applied to the excited atom or molecule.
Stimulated emission is a bit different.
A laser takes advantage of absorption, spontaneous and stimulated emission to create conditions favorable to light amplification or optical gain . When a material is in equilibrium, Boltzmann statistics describe the system and predict that nearly all particles are in the ground state. Under these conditions, the rates of absorption and stimulated emission are equal. The wavelength of the photon depends on the specific energy levels involved, but will be between 400 and 600 nm. As the above figure shows, there are many competing energy bands.