Stars are well known to have magnetic fields surrounding them like many planets do. These magnetic fields are generated due to the movement of the plasma, which is of course charged, inside the star. It is through a series of convection currents that the dynamic action of the plasma keeps going and so the magnetic field remains. As magnetic fields themselves exert forces on plasma this creates a very interesting effect where without a density change the internal pressure of the star can change. This is one of the aspects that makes the modelling of stars as perfect gasses a foolish task. Although it was believed for some time that the swirling plasma must cause the magnetic fields recent observations have shown that even the calmer, static regions of the Sun maintain a magnetic field over them.
One of the theories has been suggested is that of differential rotation. As not all parts of the sun rotate at the same speed, differing based on latitude, this difference in rotation speed is believed to act as a source for magnetic fields. Another idea is that of a fossil field that is the relic of a previous state of the star. This concept is still a bit shaky as most sources of magnetism would not remain stable when the star changes its type. It is however the best shot that scientists have at the moment.
The story starts with Ap stars which are like normal magnitude A class stars except that they have an excessive ammount of metals such as strontium, chromium and praseodymium. A combination of these metals with the slight magnetic nature of the interstellar medium (supposedly) leads to these stars being highly magnetic. Alfvén’s theorem then is called upon which says that in a fluid with infinite electrical conductivity (and a plasmas close enough) the magnetic flux leaving the surface of the fluid when it gains this conductivity must remain constant. This is known as flux freezing as if the theory is true these magnetic fields remain trapped throughout the stars entire life as it progresses to a white dwarf. Theories such as these could do with some help from numerical simulations and hopefully the theoretical rigour can be performed in the future.
Paper links: Magnetic fields in non-convective regions of stars