The kohanim and Leviim were organized into labor divisions called “mishmaros,” typically translated at “watches.” These watches performed the service in the Temple according to a scheduled rotation. Sefer Divrei HaYamim (the Book of Chronicles) explained how King David organized the kohanim and Leviim into 24 weekly shifts, each of which would end up serving two weeks out of the year. The exception to these rotations was the three Festivals. On those days, all males would appear at the Temple. Being “peak” periods, all kohanim and Leviim were on duty.
Each watch had an assigned head, who would divide his watch by family groups to do the necessary work. The watches would change on Shabbos. The prophets instituted 24 groups of Israelites, called “ma’amados,” to correspond with the mishmaros. The ma’amados would engage in prayer, fasting and Torah on behalf of the people.
The reason underlying this mitzvah is basic human nature. When somebody has responsibility for something, he’s more likely to step up to the task. If there are tons of people around who “could” do it, it’s far more likely that everyone will abdicate responsibility with the result that the job goes un-done, or done poorly. Having the various watches of priests and Levites responsible for their assigned turns helped to invest them in the process.
Ramban (Nachmanides) does not consider the mishmaros one of the 613 mitzvos, but a law given orally at Sinai, for which the verse serves as a mere allusion.
This mitzvah applies to male kohanim and Leviim in Temple times. It is discussed in the Talmud in tractate Succah on page 55b and is codified in the Mishneh Torah in the fourth chapter of Hilchos Klei HaMikdash. This mitzvah is #36 of the 248 positive mitzvos in the Rambam’s Sefer HaMitzvos.