Protecting the Sanctuary was a sacred duty that demanded constant vigilance and daily readiness from the Levites assigned to guard it. To ensure they were always close at hand during their shifts, these guards slept around the perimeter of the Temple [מצודת דוד, ביאור שטיינזלץ]. Staying overnight on the grounds was essential for their specific task of nighttime security [מלבי״ם]. This heavy responsibility was a direct fulfillment of the obligation to guard the House of God, an assignment originally commanded in the Book of Numbers [רלב״ג].
The duties of the Levites extended beyond the night watch. As the ones entrusted with the keys to the courtyard, they held the authority and responsibility for opening the gates [רש״י, מצודת דוד]. Because the Sanctuary doors were securely locked each night, the guards had to reopen them every single morning [ביאור שטיינזלץ]. Their possession of the keys was therefore directly connected to this permanent morning routine of unlocking the gates to begin the new day [רד״ק].