According to our current understanding of the formation of planetary magnetic fields, the magnetic fields are created by convection of conductive materials, such as iron in planetary cores. Actually it is the same process that is also responsible for magnetic fields in stars, though here the convection rather happens in the outer layers.
Now Earth is significantly bigger than Mars and has a convection in the liquid core going on. This is what we believe to be the source of our magnetic field. Mars is smaller and much less active. We believe the core of Mars to be ~~completely solid, not molten~~ [at least partially liquid, but not moving](https://newatlas.com/mars-gravity-map/42430/
). This means no convection and no magnetic field. Though in the past Mars most likely was hotter and had a molten core. This created a strong magnetic field, [the remnants of which can still be found in some parts of Mars crust.](https://www.nasa.gov/centers/goddard/news/topstory/2005/mgs_plates.html
I think it's an open question.
Earth's magnetic field is generated by electrical currents in the liquid outer core, a process known as a 'geodynamo'. The latest research indicates that Mars *does* have a liquid outer core. Why that core doesn't sustain a geodynamo is unknown, though there are some hypotheses, including the idea that large impacts warmed the mantle which disrupted convection in the core shutting down the dynamo.
Mars did once have a magnetic field. It's left behind magnetised rocks in the crust which create weak magnetic fields in some places. But no global field like Earth and the gas giants have.
This is still an open question as we do not fully understand the mechanisms of dynamo theory. Contrary to popular belief Mars does in fact have a [liquid iron core](https://www.nasa.gov/home/hqnews/2003/mar/HP_news_03094.html
) so the question then is why does the Martian core not sustain the magnetic field? Has the dynamo shut off or is something else at play here?
There are two main ideas on what is happening. The first is to do with heat flux out of a fully liquid core. If the heat flux out is too high (basically the core is cooled too fast relative to the mantle) then this can shut off dynamo action.
The second is related to the potential for the Martian core to be freezing from the top down (unlike the Earth which is freezing from the bottom up hence the solid inner core). The details of this I am hazy (despite sitting through the seminar presenting the work!) but can be found [in this paper](https://arxiv.org/ftp/arxiv/papers/1709/1709.01100.pdf
) along with some details of the 1st idea.
An interesting byproduct of both of these is that dynamo action could actually start up again depending on the conditions inside the core right now.