A fantastic review in the British Journal of Sports Medicine looks at the available research evidence, and argues that dehydration and salt loss are unlikely to have anything to do with exercise-induced muscle cramps.
For example, several recent studies have examined electrolyte levels among crampers and non-crampers following endurance events. They found no differences in electrolyte concentrations between the two groups, and electrolyte levels did not change when the cramps disappeared. Similarly, cramping athletes are not any more dehydrated than their non-cramping counterparts. It’s also worth noting that “heat cramps” have been observed in cool environments, such as swimming in cold water (conversely, cooling hot a person does not make their cramps go away). Core temperature does not seem related to cramping either.
As Dr. W Edwards Deming used to say, "We know so much that isn't so."
The article goes on to suggest that fatigue is the cause of cramping, vice heat, dehydration or electrolyte imbalance.