Weird Leg muscle problems

So typically when I masturabate my legs kinda flail a bit and get in weird positions. I don't even really notice it because I'm so focused elsewhere. But sometimes I'll suddenly feel pain in one of my legs and when I go to feel my muscle it feels really tight and hard. Like it's bunching itself up or something. I stretch out my leg and eventually it goes away after a bit but the muscle will still be sore. Is it like a muscle spasm? Something else? Anyone else experienced this?