Planetary magnetic fields are definitely related to rotation, but “directly” — not so much. They are actually generated by the complex interaction of fluid currents (motion of material) and electric currents (motion of electrons) in the conducting fluid of the molten metal core. This is called a “dynamo,” and core convection is its primary driver, powered by cooling and crystallization growth of the solid inner core.
Astronomy magazine subscribers can read the full answer for free. Just make sure you're registered with the website.