That can happen from just about any kind of disturbance with sleep, even though I get it can seem scary and super-strange.
It's usually not anything to worry about, though I would mention it happens to your doctor the next time you see them, just so they can be sure that's what it is, rather than something that needs investigation and treatment, like epilepsy, for instance. (You don't have to say it happens the morning after you masturbate unless you feel comfortable doing so.)
I'm not an expert on this, but based on what I know about it, it might just be that your masturbation is disrupting your usual sleep patterns in some way. I'd just try mixing it up and seeing what happens, like maybe doing it an hour or so before sleep instead of right before, or in the morning instead. You might also try doing something like some stretches and deep breathing after -- and before you go to sleep -- to see if that helps.
Never doubt that a small group of thoughtful, committed citizens can change the world. Indeed, it is the only thing that ever has. - Margaret Mead