Most sports scientists (the others have studies funded by High 5 😉 )believe that ‘Exercise Induced Cramps’ are what occur when the neuromuscular demands of an exercise/exercises are beyond neuromuscular capabilities of a muscle or a group of muscles. Basically, your body can’t really control how muscle contractions ‘fire’ any longer, and it often inevitably means a really, really hard and long contraction of the muscle.
I often get cramps after races when sitting down at the end, which is pretty normal. Your muscles will be contracting in a different, much slower way than they were on the bike and if you pulled your leg back under a bench your hamstring may well just decide it wants to cramp.
I don’t think there’s been a study since the war that’s concluded that electrolytes prevent camp, at best weak correlations. Electrolytes are important for proper hydration though, so they have their place.