This fundamental rule is crystallized in the Rambam's words at the end of Shmita ve'Yovel:
So it's not only Shevet Levi. This exemption includes all who take upon themselves lives exclusively dedicated to study and religious service.
From this Rambam, all we know is that people who are exclusively dedicated to learning Torah are exempt from conscription. But what of people who work, but are Talmidei Chachamim? For that, we look to the Rambam in 6 Talmud Torah 10:
It appears that the concept of "Shevet Levi" applies both to those that are dedicated to exclusive Torah study and also to the Talmidei Chachamim (a contextually sensitive term whose meaning changes according to the time and place, as evident in various applications which I don't feel like looking up now.)
So it is clear that Shevet Levi did not go to war, not Milchemes Mitzva, not Milchemes Reshus, and not Milchemes Amaleik. What did they do? They learned and davenned. As the Gemara in Makkos 10a says, א"ר יהושע בן לוי מאי דכתיב (תהילים קכב) עומדות היו רגלינו בשעריך ירושלם? מי גרם לרגלינו שיעמדו במלחמה - שערי ירושלם שהיו עוסקים בתורה . But there was one and only one exception: The war with Midian, as described in our parsha. Rashi in 31:4 says לכל מטות ישראל: לרבות שבט לוי:. This is based on Rashi's girsa in the Sifri here (although the Gaon has the Sifri saying the opposite.) Rashi's Sifri is stating that Levi did not join the battle in other wars, but the war against Midian was the exception.
Another odd thing about this War is that only here are we introduced to the idea of having dedicated davenners for each soldier. What happened in the earlier war with Sichon and Og?
Of course, the two singularities explain each other.
In all other wars, Shevet Levi had the job of davenning for Klal Yisrael, and there was no need to dedicate a mispallel for each soldier. In the war of Midian, on the other hand, Shevet Levi was physically invested, just as all the other Shevatim were. If so, there was no Shevet- there was no eidah- that was completely and exclusively dedicated to tefilla and Torah. So davka in this war was there a requirement of having Anshei Ma'amad.
One more question: Why was the War of Midian different from all other wars? Why were the Leviim told to join the war on the battlefield?
The Rogotchover says that this was not a Milchemes Mitzva and it was not a Milchemes Reshus. It did not have the dinim of Milchama at all. It was, as he explains here, an action of revenge. He says it was נקמה, not מלחמה. It was an infliction of נקמת השם במדין. He says there are many halachic differences between the two. Two examples: here there was not din of יפת תואר, and there was no rule of only surrounding the enemy on three but not four sides.
In any case, I look forward for someone to explain to me why the idea of military exemption for Talmidei Yeshivos elicits such anger from other Frum Jews. I'm not talking about Tel Avivians, who, beginning at around the same age that Dati children are being taught Torah tziva lanu Moshe. are taught to abhor Chareidim. I'm curious about Frum Jews who hate the Chareidim for avoiding the draft. Of course, the system is abused, and batlanim and shkotzim and black marketers take advantage of it. But as far as I can tell, the people who disparage the Chareidim for draft avoidance do so wholesale, not retail, and feel that even yeshiva bachurim who are sincere and serious masmidim ought to be in the army.
Since it's the Three Weeks, and, as I've said, we're fated to be at each other's throats anyway, please feel free to heap invective upon me. Catharsis is good for you.
By the way: Just as the Eim Habanim Smeicha is endlessly cited in the DL community, here's someone with sterling credentials that says pshat in the Rambam like me: Rav Tikotzinsky, writing for Rav Herzog. (An epitaph for Rav Tikotzinsky is here.) You really don't need rayos that the Rambam means what he says, but there it is anyway. See also the Ambuha D'Sifri vol II page 518, or here, and the Pnei Meivin in Sanhedrin 20b, here.
Rabbi Yonoson Rosenblum mentioned this issue in an article some time ago. The full article is located here, and I quote the most relevant passage:
Even at Mercaz HaRav, long viewed as the flagship yeshiva of the National Religious world, boys are strongly encouraged to push off army service in favor of full-time learning during the crucial years prior to marriage, and for several years thereafter.
The negative objection to army service derives from the use of the Israeli army as an instrument of socialization. Chareidim have no desire to have their children socialized to norms antithetical to the Torah and in a spiritually threatening environment. Israel, for instance, has long been the only non-revolutionary society to draft women. The recent push to integrate women into combat units has caused many even in the national religious world to reconsider the propriety of army service.
Nor can we control the irrational aspects of the hatred. A certain antipathy to the Torah and those who learn it is built into the Creation. Where does the name Sinai come from? Chazal ask. They answer: From there sina (hatred) came into the world (Shabbos 89b).
Here's an abstract of some fellow's master thesis at an American college. Found here.
The haredim in Israel are an ultra-Orthodox Jewish religious group who uphold the most conservative of Jewish laws. Instead of serving in the Israel Defense Forces (IDF) as all other Israelis do, the haredim are exempted from the IDF's policy of universal conscription. This thesis proposes three hypotheses to determine why Israel's haredim do not serve in the IDF. First, the haredim do not serve in the IDF because they do not want to; second, the haredim do not serve because they hold pacifistic political opinions; and third, the haredim do not serve because Jewish religious tradition forbids military service. To test these hypotheses, data were gathered by conducting a literature review and studying Israeli newspapers, official Israeli Government statistics, and unofficial public opinion surveys. Accordingly, a close examination of both the haredi worldview and the cultural characteristics of Israel's haredi communities suggests that the haredim do not want to serve in the IDF for self-interested reasons. Furthermore, a survey of haredi political opinions indicates that the majority of haredim exhibit a hawkish and aggressive political orientation. Finally, an analysis of individual haredi voices reveals that haredi yeshiva students consider their Torah studies to be an integral component to Israel's wartime activities. Contrary to the expectations of this thesis, haredi resistance to military service is not defined by an aversion to war or a commitment to peace, and it therefore cannot serve as a model for advocates of conflict resolution to emulate.
And finally, reporting from Yediot Achronot..........
Activists protest haredi draft dodging - Israel News, Ynetnews