Spokes break for the same reason any other material does: they are subject to stresses they are unable to withstand.
In the case of a wheel, it can be overloaded by rider weight, cargo, or forceful impacts. Additionally, the presence of loose spokes results in other, properly tensioned spokes bearing more of the wheel's load. Spokes are under tension, so loose spokes are subject to larger swings in stress as they are loaded and unloaded as the wheel rotates. This cycling fatigues the spoke material and can lead to failure.
All of these can be compounded when the spokes are materially compromised from corrosion or other forms of damage.