Do not go out the door of the tent of meeting… (Leviticus 10:7)
As with the prohibitions against unruly hair and torn clothes in the previous two mitzvos, this mitzvah is repeated with specific reference to the Kohein Gadol in parshas Emor (Leviticus 21:12). There, the Torah specifies that doing so would be a desecration. This makes it more clear that the prohibition is to exit during the service, since then there’s something going on that could conceivably be desecrated. (Logically, there has to be some limitation to this command; it’s not as if the kohanim were never permitted to leave!)
The context of this mitzvah as stated in the Torah is that a kohein may not leave the service to attend a funeral. It would be a desecration for him to stop the service for any worldly matter. To do so would send the message that there’s something that “outranks” the service of God. As such is not the case, a kohein may not leave the Temple while the service is in progress.
Even though no kohein was to leave the Temple upon hearing of a death, only the Kohein Gadol was to keep on performing the service. Other kohanim were not to work because they were in a state of aninus (the period after the death of a close relative but prior to the burial). The only reason the Kohein Gadol would keep working in such a case is because of the details of his obligation in 21:12, “he shall not profane.”
This prohibition applied to male kohanim in Temple times. It is discussed in the Talmudic tractate of Zevachim (16a-b), as well as in Sanhedrin (19a, 84a) and Horiyos (12b). It is codified in the Mishneh Torah in the second chapter of Hilchos Biyas HaMikdash. It is #165 of the 365 negative mitzvos in the Rambam’s Sefer HaMitzvos.