Why doesn't oxygen replace chlorine? If oxygen is more electronegative why doesn't it replace chlorine in compounds?

Example:

$\ce{2NaBr + Cl2 -&gt; 2NaCl + Br2}$

works, while

$\ce{4NaCl + O2 -&gt; 2Na2O + 2Cl2}$

doesn't.
You can displace chlorine from hydrogen chloride.

With sodium chloride, if you did form sodium oxide it would be a strong base.  As such it extracts a $\ce{Cl^+}$ moiety from any potential chlorine molecules.  Sodium chloride is oxidized by oxygen, but the oxidized chlorine ends up as hypochlorite oxyanions such hypochlorite (i.e., oxide coordinated to chlorine).