Sharp, severe pain that comes on suddenly when the person is nearing orgasm, is a sexual headache known as "orgasmic cephalgia".
It's not that common, but it does occur and it's quite distressing to those who have them (men are three times more likely to suffer from sexual headaches)
The precise cause is not well known, but probably it's a type of "exertion" headache, in which the pain comes on during vigorous physical activity.
During sex (or vigorous exercise), body releases catecholamines, chemicals that increase metabolic activity and it's possible that these chemicals could act as a trigger on the blood vessels in susceptible persons, or that the chemicals could act on certain sensitive areas of the brain to trigger a headache.
Men who get sexual headaches, also tend to suffer from migraine headaches.
Do you get the sexual headaches very frequently?