S-p mixing is the primary cause of the difference in the molecular orbitals of nitrogen and oxygen, which is influenced by the initial atomic orbital energies.
The lighter second period elements (prior to oxygen) have a relatively small difference in energy between the 2s and 2p orbitals. This allows sufficient s-p mixing to lower the energy of the σ(2s) and σ*(2s) molecular orbitals, and is energetically offset by an increase in energy of the σ(2p) and σ*(2p) molecular orbitals. In the dinitrogen molecular orbital scheme, the dashed lines are there to represent s-p mixing influencing the energy of the four molecular orbitals involved.
The effective nuclear charge increases to the right of the period, stabilizing the 2s orbital more drastically than the 2p orbital. This can be seen qualitatively in the first figure here.
The more stabilized 2s orbital does not s-p mix as effectively, due to the greater energy difference between the 2s and 2p orbitals. As nuclear charge increases, s-p mixing becomes less significant. The change of the molecular orbital ordering between nitrogen and oxygen is the manifestation of this decreased s-p mixing. In the dioxygen molecular orbital scheme the s-p mixing effect is no longer significant enough to alter the relative orbital arrangement.
More information about the details of this difference can be found in most inorganic chemistry textbooks. There are good diagrams showing the gradual change in energy differences across the second row range of homonuclear diatomic molecules. This document highlights the progressive lowering of molecular orbital energies due to the the atomic orbital changes, and presents a correlation diagram linking internuclear separation with molecular orbital energies as well.