Well now you made me go and google it. Some snippets from the top results:
Evolution. Most female mammals have an estrous cycle, yet only ten primate species, four bat species, the elephant shrew, and one known species of spiny mouse have a menstrual cycle. As these groups are not closely related, it is likely that four distinct evolutionary events have caused menstruation to arise.
Also:
To understand why menstruation evolved, we have to think of it as a by-product of spontaneous decidualisation. In most mammals, decidualisation – the thickening of the uterine wall – is controlled by the embryo: it occurs in response to fertilisation rather than in preparation for it. In menstruating species like humans, spontaneous decidualisation is one way the parent tries to wrest back dominance of their uterus from an increasingly invasive embryo. The uterine lining now responds only to the parent’s hormones rather than the embryo’s, and the parent controls whether or not they get pregnant. They put their defences up preemptively, by sealing off the main blood supply from the endometrium before the embryo implants there. Not content with this, the embryo evolved to burrow through the endometrium until it reaches the arteries, where it tears through the wall and rewires the blood vessels so that it can bathe directly in the parent’s blood. The (arguably) ungrateful parasite pumps out hormones to make the arteries expand around it, and paralyses them to prevent the parent from cutting off its supply. It produces more hormones, which act directly on the parent to maintain pregnancy and increase the availability of nutrients. The parent defends themselves as best they can: their endometrium fights against the embryo’s invasive proteins, their immune system attacks the invading cells, and their own hormones try to counteract those of the embryo. The tug-of-war rages on.
Well that’s just metal af.
https://en.m.wikipedia.org/wiki/Menstruation_(mammal)#:~:text=in human females.-,Evolution,have caused menstruation to arise.
https://eusci.org.uk/2020/04/09/why-do-humans-and-so-few-other-animals-have-periods/
Disclaimer: I can’t vouch for the factuality of any of it. It’s just the top search results.