Cramp is one of those issues that still has sports scientists scratching their heads. One long-standing theory cites electrolyte loss/imbalance as the most likely culprit, but another more modern theory is that neuromuscular fatigue could play a central role when muscles involuntarily contract. The latter seems more likely in the swim phase of a triathlon where electrolyte imbalance shouldn’t be occurring, and could be down to you working your muscles very hard for an extended period of time.
If neuromuscular fatigue is the main issue then training more specifically (i.e. with longer and harder efforts at race pace, under race-type conditions) should help as it will condition the muscles to cope. It may also be worth getting some proper sports massage on the affected muscles and topping that up with foam rolling and regular stretching to keep the muscles as supple and relaxed as possible.
Learning to relax your feet and to kick less vigorously when swimming hard could also be useful as there’s a good chance that the calf cramping is related to pointing your toes, which happens more and more the harder you kick.