I this problem and the reason - scowling/straining face muscles when putting swim cap on. Try it and see. Do you raise your eyebrows/tense your forehead when you put your cap on. If so you are locking your face muscles in a tense position and this inevitably leads to headaches. Might sound stupid, but this was my experience and since I have been careful putting my cap on, the headaches have gone. Other possibilities:
1. Goggles to tight
2. Dehydration
3. Not breathing out enough
4. Pool rage caused by breast stroker in your lane, compounded by heavy perfume!