Many of the richest and purest iron ores are found in so called banded iron formations, cm thick magnetite or hematite layers intermixed with iron poor rock layers. Since these are usually of pre-Cambrian age, the processes involved seem to preclude modern day environments.
A few elements to complement @Siv answer, and some alternatives hypotheses:
Originally the idea was that the Fe2+ oxidation into Fe3+ that lead to the formation of the BIF ("banded iron formations") was an indirect consequence of the increased atmospheric pO2 caused by the photosynthetic activity of, then freshly appeared, cyanobacteria (see e. g. Cloud 1973 which, along with Cloud 1968, are i think the first occurrence in the literature of such an idea).
Later, the idea that the cause of the iron oxidation was linked to a specific metabolic reaction involved in anoxygenic photosynthesis (i. e. a different way of fixing CO2 that does not create O2) in bacteria was also introduced (Hartman 1984; Konhauser et al. 2005).
Another possibility invoked by Holm 1989 is the active oxidation of Fe2+ by "chemolithoautotrophic" bacteria (using it directly as energy source).
Finally, the only (as far as I can see) non-bacterial hypothesis on the BIF formation is that of photo-oxidation (Braterman et al. 1983): the oxidation and precipitation of Fe2+ in Fe3+ being indeed possible without oxygen, in strongly acid conditions with a little help from UV photons.
Braterman P. S., Cairns-Smith A. G., Sloper R. W., 1983. Photo-oxidation of hydrated Fe2+ – significance for banded iron formations. Nature, 303: 163-164.
Cloud P., 1968. Atmospheric and hydrospheric evolution on the primitive earth. Science, 160, 729–736.
Cloud P., 1973. Paleoecological Significance of the Banded Iron-Formation. Economic Geology and the Bulletin of the Society of Economic Geologists, 68: 1135-1143.
Hartman H., 1984. The evolution of photosynthesis and microbial mats: A speculation on the banded iron formations. In Y. Cohen et al. (Eds), Microbial Mats: Stromatolites, Alan Liss Inc. (New York): 449–453.
Holm N. G., 1989. The 13C/12C ratios of siderite and organic matter of a modern metalliferous hydrothermal sediment and their implications for banded iron formations. Chemical Geology, 77: 41-45.
Konhauser K. O., Newman D. K., Kappler A., 2005. The potential signiﬁcance of microbial Fe(III) reduction during deposition of Precambrian banded iron formations. Geobiology, 3, 167–177.
At μ/g level some decade ago, they were explained as forming in relation to the oxygenation of the atmosphere, as photosynthetic life developed changing a reducing environment to an oxygenated one, iron oxides formed precipitating out of seawater in variable bands related to local (or possibly seasonal) oxygen availability.
Though this traditional explanation is being challenged, with research claiming the iron and silica compounds came from hydrothermal vents on the ocean floor known as black smokers. This theory has nothing to do with the oxygenation of the atmosphere, with the suggestion that BIFs may still be forming at present.