1. foreskin of the penis swells during sex and masturbation
IF there is some attachment of skin with glans, which is present during childhood but goes away as one grows older and with time, and going by your history, 'swollen foreskin' (i.e. skin is still attached with the glans) and advise for 'operation' by doctors it seems that problem is related to Phimosis,Paraphimosis
unless proved otherwise.
2. because surgery is indicated, it seems that other causes of swelling on foreskin i.e. infection, poor hygiene, contact dermatitis
, and sexual activity are ruled out!
3. going by your history (3 years) it seems that Paraphimosis is not the cause,in which foreskin is stuck before the glans penis
(cutting off blood supply to glans) and is an EMERGENCY MEDICAL condition,so probably PHIMOSIS is the Picture as for now.
4. You haven't mentioned about the symptoms arising from your Pathology (any discharge,rash,itching,) to r/o balanitis?
5.Probably doctors are advising you for 'CIRCUMCISION' operation?
6. if Phimosis is the condition then it can create problem with urination and sexual intercourse, before opting for surgery, simple method can be tried like:
i. apply 'oil' gently and regularly on the foreskin and daily retract the foreskin of penis, it will get better meanwhile.
ii. don't masturbate if you notice swelling, wait for the swelling to subside then indulge.
iii. Surgery procedure is minor, successful and harmless,and also protects against penile cancer
and Urinary tract infection
, only disadvantage being there will be less sensitivity of penis which may cause less pleasure.