Muscle stiffness can be a result of many things including water intake, muscle recovery from overexertion, or vitamin and mineral deficiencies.
There are two groups of minerals that our bodies use to contact a muscle, sodium and potassium, and calcium and magnesium. When any one of these minerals is out of balance, a shortage or excess, the muscles can become stiff. One that I typically recommend to all of my patients that are experiencing muscle stiffness especially before bed is to take a magnesium and calcium supplement and drink plenty of water. These three things can have a large impact on decreasing muscle stiffness and helping you get back to normal. As always, consult your physician before making any changes to your regime.
If your worried about electrolytes, be sure you are getting plenty of the big 5:
Best to get lab work done to determine the deficiency, then your doctor can tell you what is best to take and dosage.