Although oxygen is a stable molecule, but in upper atmosphere, sun rays break a normal molecule into two separate oxygen atom.
This highly reactive oxygen atom then combines with another molecule of oxygen to form ozone. This process occur continuously whenever ultraviolet radiation is present in atmosphere, or more specifically in stratosphere.
Reaction is:
O2 2O
O + O2 O3
, so overall reaction is
3O2 2O3