Hi Julie,
That's a really good question, and it is one that scientists are only just beginning to understand. We have known that the Sun goes through cycles of high and low activity since the 1800s, thanks to scientists like Heinrich Schwabe and Richard Carrington who recorded variations in the occurrence and number of sunspots and made observations of other kinds of solar activity, like solar flares. However, it wasn't until the 20th century that we learned that the changes in the number of sunspots and the occurrence of solar activity such as sunspots, solar flares, coronal mass ejections, and coronal holes are linked to internal changes to the magnetic dynamo inside the Sun that cause the magnetic field of the entire Sun to reverse direction every 11 years.
Kris