When I was starting out diving as a young teenager, i was prone to hamstring cramps. I was freedive spearfishing in NJ, solo and wearing a 7 mm jacket and no pants and no hood because the water was pretty warm. I did not feel cold, however the water was probably 65 or something and I was working hard swimming each fish I shot back to shore.
After several trips, as I was coming in through the surf, I was hit with a bad leg (hamstring) cramp, so I tried to swim through the surf with one leg. I guess the extra demand caused both legs to cramp. It turned me into a ball. I dropped the gun and fish and was rolling through the surf, with very little opportunity to breath. I was in terrible pain, terrified and i think I almost drowned. The surf spit me out near shore and I crawled out. I scared the hell out of me. I NEVER had such a cramp when playing football, or any sport or running or biking or even swimming on a swim team.
After that, I concentrated on leg curls in the gym, and built those hamstrings up and I very rarely get a hamstring cramp.
Personally, I think that chilling of the muscle, even if your over all body temperature is sufficient, makes the muscle much more prone to spasm. Even after 40 years from that incident, I will always wear wetsuit pants, unless the water is super warm. For years i commercially dove for lobster with 7 mm FJ pants, hood and just a nylon wind breaker for the top.
So train and stretch the specific muscle that is giving you trouble and keep it warm - is what I learned.