"First, since there is so little good research on cramps, a lot of myths have built up around the subject. So let's start with the facts. Muscle cramps are very common during (but more commonly after) exercise. There have been several theories about why they happen, including low blood sugar, dehydration, salt imbalances after sweating, and either extreme heat or cold. All of these are known to cause cramping by themselves, but it's unclear if any are the culprit with normal exercise-induced cramps.
According to current theory in the sports science literature (as of 1997), skeletal muscle cramps during exercise probably happen when muscles that are shortened (for example, a calf muscle when your toe is pointed) are repeatedly stimulated. This can happen if your foot is extended, toe pointed, and you keep extending it further. You can actively do this by, for example, running on your toes or doing lots of toe-raises without going down to extend the muscle. What appears to happen is that the muscle gets fatigued, and it doesn't relax well. There is a reflex arc -- made up of the muscle, the nerves carrying signals to the central nervous system (CNS) and the nerves carrying signals from the CNS back to the muscle -- that keeps carrying contraction signals from and to the muscle. This appears to lead to a sustained contraction in the muscle, also known as a cramp.
Stretching (in this case, grabbing your toe and stretching the calf) is about the only thing that breaks this reflex arc signal and stops the cramp when it comes to exercise-induced cases. But the muscle is still fatigued, and the cramp process is easy to re-trigger until the muscle rests for a while. The fatigue-cramp process seems to happen most often in muscles that cross two joints, such as the calf muscle (which crosses the knee and ankle), since the muscle is easy to shorten and continue contracting."