Why do human females have periods?
Short answer
Shedding or reabsorbing the endometrial lining is energetically advantageous to the female.The advantage of shedding over re-absorption may be that sperm-born pathogens are removed from the uterus. A more parsimonious explanation, however, is that the endometrium in primates has developed into too large of a structure to be completely reabsorbed by the uterus wall.   

Background
Basically you ask why are estrous cycles in mammals accompanied by regression and build up of the endometrial lining? The main reason for either reabsorbing or shedding the endometrial lining is thought to be to save energy. It has been calculated that, when implantation fails, a cyclical regression and renewal of the endometrium is energetically less costly than maintaining it in a metabolically active state required for implantation. In the regressed state, oxygen consumption in human endometria declines nearly sevenfold. Metabolic rate is at least 7% lower, on average, during the follicular phase than during the luteal phase in women, which signifies an estimated energy savings of 53 MJ over four cycles, or nearly six days worth of food (Strassmann, 1996; Crawford, 1998).

In fact, impaired shedding of the endometrial lining may lead to pathologies. If no egg is released and the estrogen/progesterone system becomes imbalanced, the endometrium may continue to thicken, instead of breaking down and being shed normally as a menstrual period. This abnormal thickening is called endometrial hyperplasia. Periodically, the thickened lining is shed incompletely and irregularly, causing irregular and more heavy bleeding. If this cycle of abnormal thickening and irregular shedding continues, precancerous cells may develop, increasing the risk of cancer of the uterine lining (endometrial cancer), even in young women (source: MSD manual).

Now the question of why human females shed the endometrial lining instead of resorbing it? Indeed, shedding the endometrium is mainly limited to primates, as opposed to reabsorbing it (like in most other mammals). Here, I do not have a definitive answer, but I like to share two opposing hypothesis on the matter.


Hypothesis 1:  Profet (1993) hypothesized that shedding the endometrium may be an effective way to get rid of sperm-based pathogens. The accompanying bleeding, Profet hypothesizes, delivers immune cells into the uterine cavity that can combat pathogens. 
Hypothesis 2: Strassmann (1996) surmises that the endometrial microvasculature is designed to provide the blood supply to the endometrium and the placenta, and that external bleeding appears to be a side effect of endometrial regression that arises when there is too much blood and other tissue for complete reabsorption. The relatively large blood loss as seen in humans and chimpanzees can be attributed to the large size of the uterus relative to adult female size and to the design of the microvasculature in the uterus wall. 


References
- Crawford (ed), Handbook of Evolutionary Psychology: Ideas, Issues, and Applications, Psychology Press (1998)
- Profet,  Quarterly Rev Biol (1993); 68(3): 355-86
- Strassmann, Quarterly Rev Biol (1996);71(2): 181-220