She may not touch anything holy or enter the Temple… (Leviticus 12:4)
In the previous mitzvah, we said that a woman who gives birth has a period of 7 or 14 ritually unclean days (depending on the gender of the child), followed by a period of 33 or 66 clean days (again, depending on the baby’s sex). While the woman was clean of niddah restrictions, there was still an aspect of ritual impurity to her status, namely that she could not eat sacrificial offerings or enter the Temple. This restriction is equally true of any person who has become ritually impure until such time as he immerses in a mikvah and the sun goes down.
The reason for this mitzvah is to instill proper reverence for the Temple and the sacrifices. It’s unseemly for a person to enter the Beis HaMikdash or eat from the korbanos in a state of uncleanliness. To do so carries a penalty of kareis (spiritual excision). If a person entered the Temple or ate from a sacrifice after immersing but before sunset, he would not be liable to kareis but he would receive lashes.
This prohibition applied to both men and women in Temple times. It is discussed in the Talmudic tractates of Makkos (14b) and Zevachim (33b). It is codified in the Mishneh Torah in the eighteenth chapter of Hilchos Pesulei HaMukdashin. It is #129 of the 365 negative mitzvos in the Rambam’s Sefer HaMitzvos.