There are many reasons which may lead to a headache following a swim.
Generally it is not a serious condition, but a result of incorrect swimming technique or bad habits as described below. If you follow these recommendations, and still have a headache, please consult a doctor.
What is the most common cause of headaches in swimmers who are not yet fully fit?
Novices and the not so well trained swimmers often exhibit a bad breathing pattern. As a result, on the one hand carbon dioxide formed in your working muscles cannot be expelled, and, on the other hand, your body does not get enough oxygen. This makes for double trouble and can give you a headache. And what is the underlying reason of this bad breathing behaviour? Fear! Fear of getting water into your face, or worse, into your lungs. It's really hard to fight this reflex. Some try to compensate by craning their head out of the water like a swan. You can see what happens to your body balance here.
How can I prevent headaches? Improve your head position and breathing technique!
And what can you do? Learn body balance, feel relaxed at the surface. Learn to lift your body (not your head) for breathing in breaststroke and butterfly (by the way, I find the notion of butterfly incorrect, I prefer that we call this stroke more correctly dolphin which is the word for butterfly technique in German). Or, rotate body and head (freestyle) with no lifting so you feel relaxed. This needs some time, patience and lots of practise. For instance, don't lift your head in freestyle to get air. Your hip has to remain at the surface. Perfect body balance and maintaining a streamlined position reduces resistance (Tip: Efficient Freestyle Swimming). By the way, never try a pull-buoy. Pull-buoys prevent you from learning proper body-balance, the only thing they do is to compensate your mistakes in a bad way creating bad body balance habits. Give it to your foe or throw it into a re-cycling bin. Or paint it into a fish and put it on your desk inspiring you to swim...
What are the most common causes among good swimmers?
Good swimmers perspire more than they think, even in the water. This leads to dehydration and lack of sodium chloride, mainly when the water and weather is warm. As a rule of thumb, you should replenish fluid loss at least with a litre (a "litre" is bit more than a quart) and 1 gram of salt (1/4 teaspoon) per hour. Please check with our rehydration tips for swimmers. Another reason with the well-trained is too abrupt a change from heavy exercise to rest. Swimming workouts are not meant to finish with sets in the anaerobic range (high heart rate above threshold) but should fade out with recovery lap-swimming (heart rate 100-120) for 5 to 10 minutes.