What we know for sure: foetuses produce hormones to keep the endometrial tissue from thinning. Once a zygote has implanted, the mother's hormones are thus no longer in control of whether her uterus will support its growth or not. Menstruation, when it happens, forcefully cleans out implanted zygotes, returning the uterine hormonal balance to normal.
What we guess that that implies: menstruation is a side-effect of enabling spontaneous abortion (miscarriage) of a still-live foetus, thus allowing females of those species to not have to go through the "avoid males you're not interested in during estrus" dance that most animals do. This confers social advantages.
In humans specifically, estrus is hidden completely from both male and female awareness. This confers further social advantages, but only could have evolved to fixation if the sexual-selection advantage of applying a "proximity during estrus" filter was completely outmoded/obviated by miscarriage.