Nighttime leg cramps can be caused by dehydration, muscle fatigue, electrolyte imbalances, or certain medical conditions.