Thanks for your query.Based on the facts that you have posted it appears that you get pain on attempting to retract your foreskin over glans penis
This is due to partial Phimosis
Retraction of foreskin on erection is important aspect in sexual intercourse and satisfaction of sexual enjoyment.
There is risk of developing paraphimosis
if you attempt it to retract forcefully.
Please consult qualified Urologist
or General Surgeon
for evaluation .You need to get circumcised. It is simple surgery carried out under local anaesthesia and will solve your problem permanently.