Physicians will sometimes prescribe a hormonal regimen (in the form of a hormonal contraceptive like the Pill) to treat certain gynecological problems like heavy menstrual bleeding, dysmenorrhea (painful periods), PMS (pre-menstrual syndrome), endometriosis, or other conditions like severe acne. In these cases, the Pill is used not as a contraceptive, but as a therapy for a medical condition.
This can be morally permissible under the principle of double effect, which allows for the treatment of a serious medical problem (the good effect), while tolerating its unintended consequences, when other less harmful treatments are not available. In this case, the unintended consequences would be the impeding of one’s fertility and the potential health risks and side effects of the Pill (the evil effect).