Sounds like a muscle fatigue cramp due to over-exertion. Has nothing to do with electrolytes or dehydration.
Essentially, your body was telling you that you were pushing yourself to the limit.
Solution? Ride more. If/when you get another cramp like this, listen to your body and back off, even if it means being dropped.