Unilateral headache during masturbation esp at climax may be related to variant of migraine as dopamine surge might be the reason. Since you ask for medical advice i assume your headache might be significant with pain persisting atleast beyond the completion of the activity.
Next Steps
if pain intensity is severe consult a doctor, you might need meducation. otherwise you may hold your practice for few weeks, reassure yourself, alter the environment and stimulus and restart when you feel doing better.