Above accepted answer provide very good explanation to the question. I did some research on it and found some reasons why Ozone layer stays there instead somewhere else.
TL;DR : Higher the altitude, higher the solar radiation energy. That makes ${O_2}$ more excited and easier to break ${O-O}$ bond. Also the concentration of oxygen need to be sufficient, but higher the altitude lower the oxygen as atmosphere become less dense. The equilibrium is where the Ozone layer is.
Following image from NASA Ozone Watch shows the $\ce{O_3}$ concentration with altitude

Center for Coastal Physical Oceanography's website has some nice explanation why 40km altitude has highest $\ce{O_3}$ concentration.
Ozone photochemistry is driven by the interaction of the Sun's
radiation with various gases in the atmosphere, particularly oxygen.
The understanding of the basics of ozone photochemistry began with
Chapman (1930), who hypothesized that UV radiation was responsible for
ozone production and proceeded to lay the foundation of stratospheric
photochemistry: the Chapman reactions. He proposed that atomic oxygen
is formed by the splitting (dissociation) of $\ce{O_2}$ by high energy
ultraviolet photons (i.e., packets of light energy with wavelengths
shorter than 242 nanometers) via
$\ce{O_2 + hc/\lambda -> O + O}$
Where h is the Planck constant, c is the
speed of light, and ${\lambda}$ is the wavelength of the photon, given in
nanometers (abbreviated nm, where 1 nm=10-9 meter). Collectively,
$\ce{hc/\lambda}$ represents the photon of light that breaks up the $\ce{O_2}$
molecule. The top panel of Figure 5.01 displays the absorption cross
section for oxygen multiplied by 10,000. The cross-section is
proportional to the probability that a photon from the Sun will be
absorbed by an oxygen molecule. While this probability increases for
the shorter, more energetic photons, the amount of UV radiation with
wavelength shorter than 242nm reaching into the atmosphere falls
dramatically with decreasing altitude.
The bottom of Figure 5.01 shows the amount of solar energy per unit
area (the flux) of different wavelengths reaching to three different
altitudes: the top of the atmosphere, 30 km, and the surface. The
amount of very energetic UV (< 242 nm) radiation falls off sharply.
Thus, the splitting apart or photolysis of oxygen molecules by solar
radiation is relatively slow in the lower and middle stratosphere
because the photons of sufficient energy have already been absorbed by
molecular oxygen in the upper stratosphere in the Chapman reaction
given above. Few such photons are able to penetrate deeply into the
atmosphere
Figure 5.01 is below
