The Rosetta Orbiter Spectrometer for Ion and Neutral Analysis (ROSINA) instrument onboard the Rosetta spacecraft has measured molecular oxygen (O2) in the coma of comet 67P/Churyumov-Gerasimenko (67P/C-G) in surprisingly high abundances. These measurements mark the first unequivocal detection of O2 in a cometary environment. The large relative abundance of O2 in 67P/C-G despite its high reactivity and low interstellar abundance poses a puzzle for its origin in comet 67P/C-G, and potentially other comets. Since its detection, there have been a number of hypotheses put forward to explain the production and origin of O2 in the comet. These hypotheses cover a wide range of possibilities from various in situ production mechanisms to protosolar nebula and primordial origins. Here, we review the O2 formation mechanisms from the literature, and provide a comprehensive summary of the current state of knowledge of the sources and origin of cometary O2.