Why has SpaceX chosen methane to fuel its Raptor rocket engine? Robert Goddard’s first rockets used liquid oxygen O2 or LOX and gasoline. The Saturn V moon rocket first stage used LOX and refined kerosene. The Saturn V second stage used LOX and hydrogen that burn to water in my favorite chemical reaction, 2H2 + O2 → 2H2O. Methane CH4, gasoline (a C7H16 to C11H24 blend), and kerosene (a C12H26 to C15H32 blend) are all linear hydrocarbons CnH2n+2 that burn to carbon dioxide and water (and residual carbon if the burning is incomplete).
Hydrolox is most efficient but requires huge tanks (due to hydrogen’s low density), which must be cooled to just a few degrees above absolute zero. Kerolox is less efficient but needs smaller tanks (due to kerosene’s high density), which can be at normal temperature and pressure. Methalox is a compromise. But unlike kerolox, methalox does not coke the engines with residual carbon that makes reuse more difficult. Also, to improve efficiency, SpaceX will densify the oxygen and methane by cooling them to just above their freezing points (rather than just below their boiling points).
However, the real advantage of methalox is that it can be manufactured from carbon dioxide and water by CO2 + 2H2O → CH4 + 2O2 on Mars.