The answer is prostaglandins. These are the chemical signals girls' and women's bodies make and send to the uterus to tell it to contract, thus expelling the uterine lining at the end of the menstrual cycle. Prostaglandins aren't super picky about whom they talk to, however. If the body sends enough of them to the uterus, some stray prostaglandins will make it over to the bowel, which is located nearby. There, they also tell the bowel to contract, thus expelling… you know.
Not all women experience more frequent bowel movements when they have their periods. Some girls feel the effects of prostaglandin on their bowels as nausea. Others actually get diarrhea. Still others are not so bothered at all.
Some women's bodies are just overzealous in their prostaglandin production.
Incidentally, those who get painful cramps can blame high levels of prostaglandins. Some women's bodies are just overzealous in their prostaglandin production. This makes the uterus contract more strongly. During especially strong contractions, the blood supply to the uterus gets cut off, causing pain.
Another reason some women poop more during their periods is because their progesterone levels fall. Progesterone is a hormone whose levels cycle with the menstrual cycle. Normally, at the middle of her cycle, a woman's progesterone levels are high. Just before her period, however, the levels drop suddenly, which helps kick off the period. Progesterone is naturally a bit constipating, too, so its sudden decline can make you feel like you really gotta go.
If a woman uses hormonal birth control—one in five women of childbearing age in the U.S. do—then her hormone and chemical levels are a bit different. Hormonal birth control often reduces how much prostaglandin the body makes, which is why it reduces painful cramps. That also means the prostaglandins aren't at work making women poop.
Nevertheless, a woman taking birth control may still feel some gastrointestinal effects just before her "period." Many birth control pills have a series of placebo pills that don't have any hormones in them, which patients are supposed to take once a cycle. Most modern birth control pills have some kind of synthetic progesterone in them. So when patients take their placebo pills, their progesterone levels fall suddenly and… voilà.
Popular Science thanks Kathryn Clancy, an anthropologist who studies menstruation at the University of Illinois, Urbana-Champaign, for her guidance in answering this question.
Have a burning science question you'd like to see answered in our FYI section? Email it to firstname.lastname@example.org.