Another interpretation: "And like implanted nails" (Ecclesiastes 12:11). From here the Sages said: It is forbidden to read in the outside books, as it is stated, "like implanted nails" (msmrot). Just as the watches (mishmarot) of the priests are twenty-four, so too the books are twenty-four. "The masters of assemblies" (ibid.) — these are the Sanhedrin. And if you should say: This one permits and that one forbids, and this one declares unfit and that one declares fit, and this one declares unclean and that one declares clean — Rabbi Eliezer obligates and Rabbi Yehoshua exempts, the House of Shammai forbid and the House of Hillel permit — to whom shall I listen? Even so, "they were all given from one shepherd" (ibid.).
The Twenty-Four Books and the One Shepherd in Tanchuma
Midrash Tanchuma Buber, Beha'alotcha 25:2
ד"א וכמסמרות נטועים, מי כאן אמרו חכמים אסור לקרות בספרים החיצונים, שנאמר כמשמרות נטועים, מה משמרות הכהנים עשרים וארבע, אף הספים עשרים וארבע, בעלי אסופות (שם), אלו סנהדרין, ואם תאמר זה מתיר וזה אוסר, וזה פוסל וזה מכשיר, וזה מטמא וזה מטהר, [ר' אליעזר מחייב ור' יהושע פוטר], בית שמאי (מחייבין) [אוסרין] ובית הלל מתירין, למי אשמע, אף על פי כן כלם נתנו מרועה אחד.