After I masturbate, I sometimes get another erection and it sort of hurts. Why?
First, your erections are caused by blood being trapped in your penis, causing it to inflate. However, after a while the oxygen in that blood is used up and the cells inside your penis begin demanding oxygen. You perceive that as pain. That is why a guy typically can't hold an erection for much more than thirty minutes. To get an erection right after the last one doesn't give it enough time to recover.
Related to that, there are several internal muscles that come into play when you have erections and ejaculate. One is the muscle that clamps down on the exit veins in your penis to cause the erection. Another closes off the bladder and opens the pathway to the ejaculatory duct. Of course, there are also muscles around the ejaculatory duct itself that causes the semen to shot out. When you have another erection, all these muscles are gearing back up for work right after working. They are sore, haven't had a chance to rest, and they are grumbling about the demand.
A third reason is that an ejaculation squeezes out semen from the seminal vesicles. To have another erection soon after ejaculating causes the body to get prepared for another ejaculation, but that means squeezing out more semen from glands that are pretty much empty. That too is perceived as uncomfortable.
Finally, the nerves in your penis, especially the glans at the end, are frazzled from the sexual excitement. They are hypersensitive after an ejaculation, so any touch or even the inflation of the penis, is perceived as painful.
Your body is just reminding you that you need a bit of time to recuperate.