If a photon hits an already excited atom, it can make it to de-excite and also eject another photon. That is induced emission. This new photon will have the same properties (phase, direction) than the original one.
If more than 50% of the atoms are excited, this causes an exponential increase of the photons in the system, all in the same phase and direction.
The cavity length must be an integer multiple of the photon wavelength, with mirrors on both ends. (One of the mirrors can be a little bit transparent, to enable the beam to get out.) To get the laser beam, the photons must be reflected many times on the mirrors.
Photons whose direction was not exactly perpendicular to the mirrors, will soon leave the system (among with the other photons they made with the induced emission). This is one of the losses which make laser beams highly ineffective.