In sexually mature people, sexually transmitted infections (STIs) are the most common risk factor for epididymitis, so anything that increases the risk for an STI also increases the risk for epididymitis, including anal sex, sex with a partner who has an STI, sex without using a condom, or a having a history of STIs.
In cases that are not related to STIs, the most common risk factors for epididymitis include:

This site offers information designed for educational purposes only. You should not rely on any information on this site as a substitute for professional medical advice, diagnosis, treatment, or as a substitute for, professional counseling care, advice, diagnosis, or treatment. If you have any concerns or questions about your health, you should always consult with a physician or other healthcare professional.