Hi,
Because they give you the densities of both O2 and Hydrocarbon at atmospheric pressure, we assume that they are both at atmospheric pressure, and because they are at the same temperature and pressure, they have the same molarity as ideal gases.
In reality for the case of measurement you would tweak your setup so that the pressures of each gas was the same, so that you could make this Molarity constant.
There's no real physical explanation for it as I agree there's no real reason for the moles to be equal, aside from careful control of the system.