In the case of the muscular cramps, the muscle contraction starts with the generation of the action potentials from the brain. The action potential causes the release of the calcium ions movement out of the sarcoplasmic reticulum (storage site of calcium). The calcium released in this process causes the contraction of the myofibrils with the help of the ATP molecules. Meanwhile, the calcium is pumped back to the sarcoplasmic reticulum through the fast calcium pumps.
The contraction of one muscle cell generate the action potential in neighboring muscle cells. When the generation of the action potential is stopped, the sarcoplasmic reticulum relaxes as well as the muscle is relaxed. The fast calcium pump is powered by a sodium gradient, and the calcium influx is a result of fast outflux of the sodium ions from the sarcoplasmic reticulum.
In case, the sodium ion is less, the calcium pumps cannot be powered, the calcium ion would remain in myofibril, as a result, the muscle would be contracted for a longer time and this result in cramps. The muscle in this case, would be relaxed by the ATP instead of sodium gradient. So, it can be concluded that the muscle cramps are caused when the muscles are not able to relax properly.