The cause of leg cramps is sometimes unknown (idiopathic). In other cases, there may be an underlying condition or another identifiable cause.
Although the cause of idiopathic leg cramps is unknown, there are a number of theories about what might cause idiopathic leg cramps. These include:
Also, tendons naturally shorten over time as a person gets older, which may explain why older people are particularly affected by leg cramps. Tendons are tough bands of tissue that connect muscles to bone. If your tendons become too short, they may cause the muscles connected to them to cramp.
Secondary leg cramps are caused by an underlying condition or another identifiable cause. These include:
Certain medications have been known to cause leg cramps in a small number of people. These include:
Contact your GP if you think your medication may be causing your leg cramps as your dosage may need to be adjusted. Never stop taking a prescribed medication unless your GP or another qualified healthcare professional who is responsible for your care advises you to do so.
SOURCE; NHS UK