We have been having periods since we can remember, as it is one of the things that comes with our evolution. But while humans experience periods regularly, it isn't something that all mammals experience. There are a few mammals that get periods monthly, and a lot of them, not at all. For example, the dog in your house doesn't menstruate, it sees what's called heat. This bleeding doesn't come from the uterus, rather it comes from the vagina and it does so before ovulation.
If I am to mention the few mammals that menstruate, I know of Elephant shrews, an African Mouse, and a few bat species. I don't think there is any other mammal that menstruates. Menstruation is a month-long cycle regulated by hormones. It starts in the uterus where the lining of the uterus is shed and expelled out of the body. Menstruation is a combination of blood, endometrial lining cells, mucus, and other tissues that are released from the body.
The period of the blood flow can differ from person to person and it can go from 3 to 7 days. The woman’s body produces tiny follicles that contain immature eggs, after which one or two of the follicles develop into mature egg cells. The mature egg is released to be held for fertilization while the non-mature eggs begin to journey through the fallopian tube. The egg is kept in the spent follicle or uterus where the corpus luteum begins to release hormones that help in fertilization, a process known as decidualization.
While decidualization happens in humans and mammals that menstruate monthly before fertilization, non-menstruating mammals only experience this when a fertilized embryo has attached to the wall of the uterus. So for humans, it is referred to as spontaneous decidualization because we do this monthly. If the egg doesn't get fertilized, the corpus luteum shrinks and dissolves and the uterus stops producing the hormone that maintains the thickness of the endometrium, thereby causing the lining of the uterus to shed.
At the end, we have come to a hypothesis that menstruation in humans is an evolutionary struggle between the fetus and its host which is the mother. While you might be curious why the word host makes it sound like the fetuses are parasites, well it is because they are parasites and the needs of the fetus might not align with that of their parents even when the parents want to have them.
Reference
https://www.msdmanuals.com/home/women-s-health-issues/biology-of-the-female-reproductive-system/menstrual-cycle
https://www.unicef.org/press-releases/fast-facts-nine-things-you-didnt-know-about-menstruation
https://www.nichd.nih.gov/health/topics/menstruation/conditioninfo
https://www.hopkinsmedicine.org/health/wellness-and-prevention/menstrual-cycle-an-overview
https://www.iflscience.com/do-animals-other-than-humans-have-periods
https://pmc.ncbi.nlm.nih.gov/articles/PMC6541669/
https://pubmed.ncbi.nlm.nih.gov/29530426/
https://www.sciencedirect.com/science/article/abs/pii/S1521693418300257