"why this happened and how to prevent it from happening again"
Tight - solid, and clean connections.
The amperage of the connections on the low voltage side of the transformer are 10X's what they are on the line voltage side. (.417 vs. 4.17) A loose connection will heat up, arching more and more over time and eventually fail.
Mark Heller "Well - I oughta....." -Jackie Gleason