I have had that happen to me when I did 20 rep squats. an extreme pain came to the back of my head and all I wanted to do was lie down in the fetal position. After taking a break for a week, I went back to squats and it came back just as strong. Sex was very painful for me too. I think I posted about my headaches on here and everybody had me worrying about aneurysms and high blood pressure. Went to the doctor, he wanted me to get an MRI...hell no.
What worked for me and many others that I researched: stretch the neck and trap muscles numerous times a day. My favorite stretch was the Levator Scapulae/Upper Trap Stretch...google it.
It could very well be an aneurysm/high blood pressure/etc, but I believe in most cases it is just tight muscles around that region.
Here's a link to the stretch:
Levator Scapulae stretch : Straight to the Bar | all things strength