Swelling and irritation come about from any form of inflammation. In your case, the apparent cause would be sex or masturbation. I think the dermatologist's suggestion that you use lubrication before sex and moisturizing/powder afterward makes the most sense. But it doesn't sound serious.
Take care.
Dr. Rockoff