I think you should see a doctor. Any new pain is worth seeing a doctor about.
Are you sexually active with another person? Do you have that pain while having sex, or is it just while masturbating? If not, maybe try changing positions, adding some lube or changing lube.
If you've been sexually active with another person, you should get checked for STIs, maybe a UTI, prostate infection.
In any case, you really need to see your doctor.