If many poor people came to a gabbai of tzedakah, and there is not enough in the purse to provide for all of them, or to clothe all of them, or to ransom all of them—they prioritize the Kohen to the Levi, and the Levi to the Yisrael, and the Yisrael to a chalal, and a chalal to a shetuki, and a shetuki to an asufi, and an asufi to a mamzer, and a mamzer to a Natin, and a Natin to a ger, and a ger to a liberated slave. In what case are these words said? When they are equal in wisdom, such that one is not much greater than the other. But if one of all these is distinguished in wisdom, and the second is minor in wisdom and certainly an am ha'aretz, regarding this the sages taught in the Mishnah of Horayot that a mamzer who is a talmid chakham precedes a Kohen Gadol who is an am ha'aretz. And even a talmid chakham for clothing, and an am ha'aretz for sustenance—the talmid chakham precedes. And even the wife of a talmid chakham precedes an am ha'aretz. And some say that in this time we do not judge so (Shach subsection 16). The general rule of the matter: whoever is greater in wisdom precedes his fellow. And if one of them was his teacher or his father, even though there are those there greater in wisdom than them, his teacher who is a talmid chakham or his father precedes the one who is greater than him. (So it appears to me to read in the Tur Shulchan Aruch section 9 (Shulchan Aruch Yoreh Deah 251, 9). And the difficulty of the Shach subsection 17 is settled, see there. And see Beit Yosef, who wrote that in the Yerushalmi at the end of Horayot it asks: Is a Levi not a Yisrael? And it answers: They taught regarding the time of the platform. Which implies that not during the time of the platform—there is no precedence of a Levi to a Yisrael. But in our Shas it does not imply so, see there. But in truth even the Yerushalmi does not intend so, for what does it ask? It is obvious that the sanctity of a Levi is more than a Yisrael. Rather the Yerushalmi stands on that of Nazir chapter seven (end of halacha 1) that a Levi and a Yisrael who encountered a met mitzvah—the Yisrael should become tamei and not the Levi. And it asks there this difficulty, because regarding tumah their law is equal. And it answers: At the time of the platform, as it is said that he should be able to go to the Mikdash. And the way of the Yerushalmi is so, to raise a difficulty on another place when it contains this phrasing as is known. And also the Pnei Moshe explained so, see there. And see Magen Avraham at the end of siman 201, and it requires further study. And from Rashi there is no proof, see there. And be precise and you will find it simple.)
אם באו עניים הרבה לגבאי של צדקה, ואין בכיס כדי לפרנס את כולם, או לכסות את כולם, או לפדות את כולם – מקדימין הכהן ללוי, ולוי לישראל, וישראל לחלל, וחלל לשתוקי, ושתוקי לאסופי, ואסופי לממזר, וממזר לנתין, ונתין לגר, וגר לעבד משוחרר. במה דברים אמורים? בזמן שהן שוין בחכמה, שאין זה גדול מזה הרבה. אבל אם אחד מכל אלו מופלג בחכמה, והשני קטן בחכמה וכל שכן עם הארץ, על זה שנו חכמים במשנה דהוריות דממזר תלמיד חכם קודם לכהן גדול עם הארץ. ואפילו תלמיד חכם לכסות, ועם הארץ להחיות – התלמיד חכם קודם. ואפילו אשת התלמיד חכם קודם לעם הארץ. ויש אומרים שבזמן הזה אין לדון כן (ש"ך סעיף קטן ט"ז). כללו של דבר: כל הגדול בחכמה – קודם לחבירו. ואם היה אחד מהם רבו או אביו, אף על פי שיש שם גדולים בחכמה מהם, רבו שהוא תלמיד חכם או אביו קודם לזה שהוא גדול ממנו. (כן נראה לי לגרוס בטור שולחן ערוך סעיף ט (שולחן ערוך יורה דעה רנא, ט). ומיושב קושית הש"ך סעיף קטן י"ז, עיין שם. ועיין בית יוסף, שכתב דבירושלמי סוף הוריות פריך: ולוי לאו ישראל הוא? ומתרץ: בשעת הדוכן שנו. דמשמע דבלא שעת הדוכן – אין קדימה לוי לישראל. אבל בש"ס שלנו לא משמע כן, עיין שם. אבל באמת גם הירושלמי אין כוונתו כן, דמאי פריך? פשיטא דקדושת לוי יותר מישראל. אלא הירושלמי קאי על הך דנזיר פרק שביעי (סוף הלכה א) דלוי וישראל שאירע להן מת מצוה – יטמא הישראל ולא הלוי. ופריך שם קושיא זו, משום דלעניין טומאה דינם שוה. ומתרץ: בשעת הדוכן, שנאמר שיהא יכול לילך למקדש. ודרך הירושלמי כן, להקשות על מקום אחר כשיש בו לשון זה כידוע. וגם הפ"מ פירש כן, עיין שם. ועיין מגן אברהם סוף סימן ר"א, וצריך עיון. ומרש"י אין ראיה, עיין שם. ודייק ותמצא קל.)