In addition to a possible allergic reaction to either the bactrim or something in the baby oil (such as a fragrance), some antibiotics can make the skin more sensitive. As a result, the bactrim could have made your skin more sensitive to the baby oil, or more sensitive to the friction from masturbation.
I would avoid the baby oil if it continues to happen, and possibly switch to a different antibiotic. If it does occur again, you may try to apply some hydrocoritsone cream to the area and take an over-the-counter antihistimine, such as benadryl.
I hope this helps!