Solar flares are caused by the release of magnetic energy stored in the Sun's atmosphere. When magnetic field lines become twisted and tangled, they can suddenly snap, resulting in a solar flare.