Why is carbon so rare on the Moon and on Mars?
Carbon is the fourth most common element in the universe and in the Solar system. It is about the ninth most common element in Earth's crust. It doesn't seem to be part of any of the ten most common compounds in the Earth's crust.
So where is all the carbon hiding?
Why isn't it more common in planetary and lunar crusts?
Is it maybe mostly occurring in volatiles together with hydrogen and oxygen, and has left bodies which lack atmosphere or freezing temperatures? Is it primarily biological processes which binds carbon to solid molecules? Having a look around on Earth's natural surface today, there's lots of solid carbon compounds everywhere, so the contrast is interesting.
There is not much doubt that the abundance of carbon in the protosolar nebula was not abnormal. We can tell that by looking at the carbon abundance in the atmosphere of the Sun - it has an abundance of 8.43 on a logarithmic (base 10) scale where hydrogen has an abundance of 12 (Asplund et al. 2009). This is typical for stars in the solar neighbourhood.
However carbon in the solids of the solar system - i.e. in the Earth, moon, meteorites etc. is underabundant with respect to this by something like a factor of 10. Nitrogen is similarly underabundant in the Earth and oxygen to a lesser extent (a factor of two). (Lodders et al. 2009)
The reason for this is that C,N,O are all capable of remaining in the gaseous phase at the kinds of condensation temperatures that are typical for forming most of the "rocks" that make up the Earth and other solids in the solar system. In particular, carbon monoxide is readily formed at high temperatures and cannot easily be captured into terrestrial planets and other rocky materials.
Maybe mention that typical rock-forming temperatures are below $~$$1200$K, while N,C,O remain volatile down to $0-200$K.
Although carbon is highly abundant in the universe, it is not homogeneously distributed. Some regions of the interstellar medium could be rich in carbon and others rich in silicon or oxygen, depending on the source of the heavier elements ("metals"). The region could be enriched from mass loss of evolved stars, or from a SN of a massive star, or from a SN from a white dwarf. Each of these bring different elemental abundances.
Also, if the region of the protoplanetary disk where the Earth formed was warm, then the carbon would be in the gaseous phase or in gaseous phase molecules like CO, CO$_2$ and CH$_4$. Perhaps, where the terrestial planets formed much of the carbon was in gaseous form rather than in dust particles, and therefore only a small fraction of the carbon was incorporated into the rocky planets.
Furthermore, much of the Earth's carbon is not in the crust. It is in trees, the atmosphere and mostly in the oceans, dissolved as carbonates and in shells etc.