Magnetic fields protect atmospheres. Prevents the solar wind from stripping off atmosphere by shielding a planet. With little magnetic field Mars lost its atmosphere, or much of it.
A molten core is needed to act as the Dynamo that creates the magnetic field. The Mars core has significantly cooled in the 4.5 billion years it has been around and even though early on it had substantial atmosphere and a strong magnetic field, today the atmosphere is extremely thin and the magnetic field weak because much less of the core is molten.
That at least is the leading theory.