Pelvic pain during the menstrual period is knows as dysmenorrhea. The #1 reason for dysmenorrhea is a condition called endometriosis, when endometrial lining is outside the uterus.
At the time of menses, hormone levels fall and uterine skin lining (endometrium) sloughs. This produces bloody menstrual tissue called menses as long as the tissue can exit the body. If there is any blockage to egress, pain is the result. Several different conditions can block menstrual egress and thus result in painful menses:
Endometriosis - endometrial tissue has implanted in the peritoneal/abdominal cavity and when the tissue is sloughed at the end of the month it has no place to go so it just stays and irritates the pelvic lining producing pain.
Primary dysmenorrhea (menstrual cramps) - the cervical opening is not large enough for the volume of menstrual tissue in a given unit of time so uterine pressure builds up producing cramps until the tissue gradually comes out
Cervical stenosis - in this case the cervical opening has some scarring due to past procedures (LEEP, cryosurgery, conization) rather than just a tightly contracted cervix found in primary dysmenorrhea
Congenital anomalies of the reproductive tract - any anomaly that blocks outflow of menses
Adenomyosis - instead of endometrial tissue being in the pelvic cavity, little islands of glands have grown down into the uterine muscle and like endometriosis, when the tissue is sloughed, it has nowhere to go and only produces an inflammatory response.