The 36th mitzvah is that we are commanded that the kohanim shall serve in watches, i.e., that each watch shall serve for one week's time. They shall not be mixed together except for the festivals, when all watches shall serve together and anyone who comes may perform the service. It is explained in Chronicles1 that Dovid and Shmuel divided them and assigned them to 24 watches.2 In tractate Sukkah3 it is explained that during the festivals, all are treated equally.
The verse which refers to this mitzvah is G‑d's statement,4 "A Levite5 can come [from one of your gates]...whenever he wishes...and may serve before G‑d, his G‑d, just the same as any of his fellow Levites whose turn it is to serve before G‑d. He shall receive the same portion to eat."
The Sifri6 says, "From the phrase, 'whenever he wishes' one could think that it means any time whatsoever. The Torah therefore says, 'from one of your gates,' i.e., when all the Jewish people are gathered at one gate7 — during the three festivals. One could think that all watches share equally during the festival even in offerings that are not specifically festival offerings.8 The Torah therefore says, 'The only exception is that which was sold by the ancestors.' What did the ancestors 'sell' to each other? They said, 'You [will serve] in your Shabbos and I in my Shabbos.' " This means that they agreed to setting up a system of watches with a different watch each week. The Targum also explains the verse in this way: "Except for the watch of that week, because that is how the ancestors established it."
The details of this mitzvah are explained in the end of tractate Sukkah.9