The Sun exhibits a periodic cycle for solar activity as manifested by solar activity (e.g. sunspots, solar flares). This activity is related to magnetic fields which emerge from the interior of the Sun. The magnetic fields are created by the solar dynamo. The Earth has a dynamo as well but the Earth's magnetic field is (mostly) constant in time. What is some current theories (assuming there isn't one already accepted) that explains for why the solar dynamo generates magnetic fields periodically?
It is linked to the solar dynamo and the dynamical behavior of the so-called $\alpha$-effect. One way to understand easily the solar dynamo and the the $\alpha$-effect with the hand is the following: you can generate a magnetic field by differential rotation (the $\Omega$-effect, $\Omega$ being the classical notation for the angular velocity). But this sole effect, twisting the magnetic field, would fold it so much that it will reconnect and dissipate. If you don't want to lose the magnetic field, you need a process to "regenerate" it, and a good way to do it is to create a poloidal component of the magnetic field. This poloidal component can be generated by convection in the solar interior; the magnetic field is, in the same time, twisted and pulled and that explains the solar dynamo.
Now, you can show that dynamo waves will propagate from the equator to the poles, and when the poles are reached, a reversal is observed. This propagation of dynamo waves is well observed by the sunspots patterns during the solar cycle.