Is abortion okay to treat endometriosis?
In this case, you are not “using contraception”; you are taking a particular medicine prescribed for endometriosis, which has the side effect of rendering you temporarily sterile. Taking this medication for the purpose of treating endometriosis is not wrong. It would only become morally problematic if you were taking the medication for the purpose of temporary sterilization (source).