Jupiter, Saturn, Uranus, and Neptune all have magnetic fields too, but are all gas giants and not really comparable.
The magnetic field of Jupiter is largely due to a core of metallic hydrogen, which exists due to the high core pressures at Jupiter’s center. Same would apply for any other gas giant of similar structure. Might also apply for brown dwarves, however there are higher core temperatures due to gravitational contraction (plus any short lived fusion reaction, either involving deuterium and/or lithium). So that further reinforces the molten core of terrestrial planets (Mars may have lost its field due to the core cooling to the point of no longer being liquid).