There's one condition that is linked to negative cognitive effects after masturbation in a small subset of population, it is called Post Orgasmic Illness Syndrome (POIS):
The sufferer experiences mental symptoms, physical symptoms, or both.
Common mental symptoms include cognitive dysfunction, intense
discomfort, irritability, anxiety, craving for relief, susceptibility
to nervous system stresses (e.g. cold), depressed mood, and difficulty
communicating, remembering words, reading and retaining information,
concentrating, and socialising.14 Physical symptoms include
severe fatigue, mild to severe headache, and flu-like and allergy-like
symptoms, such as sneezing, itchy eyes, nasal irritation, and muscle
pain.3 Affected individuals may also experience intense warmth
So to answer your question - masturbation/orgasm does negatively affect cognition in people affected with POIS. There's another condition that may be similar : Post-coital tristesse
This may/may not be related, but prolactin, a hormone with multiple functions is elevated for multiple days in males after experiencing orgasm. From wikipedia:
The hormone[prolactin] counteracts the effect of dopamine, which is responsible
for sexual arousal
I can't find a reliable source, but I read that the increase in prolactin lasts for up to 15 days following orgasm.
Looking at these dopamine and prolactin hormones on wikipedia, I saw that prolactin and dopamine suppress each other. From Dopamine article:
Dopamine is the primary neuroendocrine inhibitor of the secretion of
prolactin from the anterior pituitary gland
If abstaining from masturbation does change hormone levels, then Prolactin and Dopamine (within specific parts of the brain) would be most likely targets.