You should see a doctor to get lab tests to rule out UTI and/or STD.
To be honest, this is pretty common if when you masturbate you have friction. Or even after sex if there was friction. That is usually nothing to worry about. However, you don't say a whole lot so it is hard to know. So, the best thing to do is to see a doctor. What other symptoms do you have if any? How long has it been going on? Do you have a frequent need to urinate? That's more indicative of a UTI. But urethral irritation can cause this so try not to worry. But do see a doctor. This could be an easy and quick fix.
I am no doctor or expert but I have similar symptomns. If you have athletes foot it could be a yeast infection caused by the same fungus. Another is a hernia, or a bacterial infection. Depends I'm off to the doctors to know what exactly it is I suggest doing the same.