They must withdraw from the holy things… (Leviticus 22:2)
If a kohein became ritually impure, he was not permitted to serve for the duration of his uncleanliness. If the kohanim violate this prohibition, they are liable to the penalty of death at the hands of Heaven. That’s because our verse says that not to withdraw constitutes a desecration of God’s Name and verse 9, a few lines later, says that kohanim perish for such desecrations.
The reason for this mitzvah is what we have said before about the importance of the Temple and the need for people not to play fast and loose with the honor due to the Divine service. Everything in the Temple must be of the finest kind and ritually-impure kohanim are not among them.
This mitzvah applies to kohanim in Temple times. It is discussed in the Talmud in tractate Zevachim on pages 17a-b, and in Sanhedrin on 81b and 83a-b. It is codified in the Mishneh Torah in the fourth chapter of Hilchos Biyas HaMikdash and it is #75 of the 365 negative mitzvos in the Rambam’s Sefer HaMitzvos.