Pain during sex can have a variety of causes, from physical conditions such as endometriosis to psychological issues such as anxiety or past trauma. It can also be caused by a lack of lubrication, an infection or inflammation in the genital area, or an allergic reaction to a lubricant or material used during sex. In some cases, the cause of the pain may be hard to pinpoint, but speaking to a healthcare provider can help to diagnose and treat the issue.