The hanger must have either been weakened or faulty. All it takes is a little knock from a fall, branch, rock etc and a weakness could be introduced. These hangers must make the companies a bit of money and so aren't made to last. Aluminium once cracked will fatigue along the crack quickly, aluminium fails catastrophically.
Crunching the gears under power gives a few kilos of force, plenty to break a weakened mech hanger. Before the days of replacement hangers as standard, I have snapped chromoly steel hangers. Biggest sinners for doing the damage are transporting the bike without the wheels in the back of a car or a low speed minor fall.
I'd recommend getting a replacement and a spare to carry. Sods law dictates that if you always carry a spare, it'll never snap again.