What exactly was it in the ancient Martian atmosphere that made it red? Was it water, molecular oxygen or something else?
The red color of Mars is due to hematite presence, Fe3+2O3, in the martian soil and atmospheric dust.
The size and concentration of the hematite particles present in a layer determines its color.
Hematite is a ferric oxide (α-Fe2O3), naturally occurring in three forms, mainly depending on the particle size of the samples (Lane et al., 1999): nanophase (dark purple, ∼<0.01 μm-diameter), fine-grained (red, diameter between about 0.01 and 10 μm), and coarse-grained (gray, ∼>10 μm-diameter).
Pure crystalline hematite particulate samples with grain sizes between 0.01 μm and 10 μm (hereafter, normal red hematite samples) exhibit reflectance spectra that are saturated (near zero) in the violet and ultraviolet and steeply increase throughout the visible spectral range. This behavior explains the typical red color of this kind of hematite.
(Marra et. al, 2011).
There is no need of a high concentration of fine-grained hematite to give the layer a red color.
Answering your question about the oxygen origin, martian soil is full of Fe-bearing compounds that, over the eons, have reacted with trace amounts of oxygen and water vapor in Mars' atmosphere to form iron oxide (source: science.nasa.gov).
The Fe-rich compounds include a large variety of minerals. Analysis of Martian meteorites suggests that the planet's mantle is about twice as rich in iron as Earth's mantle (source: Composition of Mars, Wikipedia.org).
The superficial wind erosion of soils enriches the Martian atmospheric dust with fine-grained hematite, giving the Martian sky and soil their red appearance.
Of particular interest to scientists is the formation of coarse-grained (grey) hematite spherules. Shao et. al, 2022 suggest that the erosion of spherules may have contributed to the fine-grained (red) hematite dispersion.
The origin of hematite nodules has been widely debated. You can find many papers discussing it, leading to some nice studies of Hawaiian hematite spherules.
- There was water on Mars.
Hydrothermal or aqueous diagenetic processes (sedimentary origin) have been proposed as the origin of iron oxides.
Shao et. al, 2022:
The mechanisms of hematite spherule formation on Mars have been widely evaluated to understand the Martian surface conditions and their history. These Martian hematite spherules was suggested to have a sedimentary origin, with the spherules predicted to have formed in solutions through precipitation. In this study, we investigated the formation mechanism of hematite spherules on Mars by performing oxidative hydrothermal alteration experiments using reproduced I-type cosmic spherules. Our results suggest that Martian hematite spherules were formed by oxidation of Ni-bearing metallic spherules produced by ablation of iron meteorites during their entry into the Martian atmosphere. After long-term exposure on the surface of Mars, most spherules were pulverized because of oxidation. Some hematite fine grains blended into the Martian soil and were moved by storms, whereas others maintained their initial spherical shape with a high content of Ni. Notably, the precursor of Martian hematite spherules may be metallic spherules derived from iron meteorites.
Sexton et. al, 2017:
By comparing our measured freezing rates with empirical and theoretical values from the literature, we conclude that the spherules on Mars could not have been produced through the freezing of aqueous hematite nanoparticle suspensions; ice crystallization front instability disrupts the aggregation process and prevents the formation of mm-scale continuous aggregates.
-A.C. Marra, M.D. Lane, V. Orofino, A. Blanco, S. Fonti (2011),"Midinfrared spectra and optical constants of bulk hematite: Comparison with particulate hematite spectra", Icarus, Volume 211, Issue 1, Pages 839-848, ISSN 0019-1035, https://doi.org/10.1016/j.icarus.2010.09.021. (https://www.sciencedirect.com/science/article/pii/S001910351000374X)
-M.R. Sexton, M.E. Elwood Madden, A.L. Swindle, V.E. Hamilton, B.R. Bickmore, A.S. Elwood Madden (2017):"Considering the formation of hematite spherules on Mars by freezing aqueous hematite nanoparticle suspensions", Icarus, Volume 286, Pages 202-211, ISSN 0019-1035, https://doi.org/10.1016/j.icarus.2016.10.014. (https://www.sciencedirect.com/science/article/pii/S0019103516301567)
-Huimin Shao, Hiroshi Isobe, Ginga Kitahara, Akira Yoshiasa (2022):"Formation of hematite spherules from metallic spherules by oxidative hydrothermal alteration: Implications for hematite spherules on Martian surface", Planetary and Space Science, Volume 222, 105565, ISSN 0032-0633, https://doi.org/10.1016/j.pss.2022.105565. (https://www.sciencedirect.com/science/article/pii/S0032063322001519)
Volcanism+Water=Acid rain is the answer to this question.
And now you all know where the free oxygen came from, it is from the acid.
Mars is believed to have had a similar chemical composition as Earth had during the formation.
If you add water to the atmosphere of Mars now you will make carbonic acid that will continue to form oxides on Mars.