The opening Posuk of this Parsha indicates that Hashem spoke to Moshe in the Midbar, the desert (במדבר א':א'). The Midrash in BeMidbar Rabbah (פרשה א' סימן ו') states that Hashem gave the Torah via three things, namely, fire, water and the desert; Pesukim are then cited which support this statement about these three things, and the Posuk in our Parsha (שם) is brought as the proof that the Torah was indeed given via the desert. The Midrash (שם) then explains that specifically these three media were selected because they are available חנם, free of charge for all who want them, as elaborated upon by the Eitz Yosef (שם בד"ה מה), and so too are the words of the Torah available free of charge to all who want to know them. In a similar vein, the Gemara in Bechoros (דף כ"ט.), commenting on the statement in the Mishnah (שם) which implies that it is forbidden for a judge (who must render a decision in accordance with Halacha) to accept payment for his actions as a judge, explains that to get paid for making Halachic decisions and for Talmud Torah, as elucidated by Rashi (שם בד"ה מנא), is improper, because the Torah elsewhere (דברים ד':ה', ועיין בתורה תמימה שם אות ו') implies that Hashem taught Moshe Rabbeinu the laws of the Torah for free (and Moshe subsequently taught this Torah to the Jewish people for free). Since the Torah was taught for free at that time, so too must anyone who teaches the Torah at any time do so for free, so that the Torah's words will be available to all who wish to learn them (מה אני בחנם אף אתם בחנם). This idea also appears in the Gemara in Nedarim (דף ל"ז.), where the Ran (שם בד"ה וכתיב) explains that Moshe was actually commanded to teach the Torah to the Jewish people for free, while the Rosh (פי' הרא"ש שם בד"ה מה) adds that this is because Hashem taught him the Torah for free; the Maharsha (חדושי אגדות שם בד"ה דכתיב) clarifies precisely how this lesson is derived from the Posuk in the Torah (שם). It thus seems clear that one is not allowed to accept payment for teaching Torah.
In general, the Mishnah in Pirkei Avos (פרק ד' משנה ה') states that one may not use the Torah for self-glorification or for self-gain, and that one who does use the Torah for personal benefit is considered to be removing himself from this world. The Bartenura (שם בד"ה ולא) explains that one should not make a job out of Talmud Torah in order to make a living from it, because one who does so is infringing upon the Kedushah of the Torah and deserves to be put to death by Hashem; he then quotes the above cited Posuk in the Torah (דברים שם) to stress that one should not receive payment for teaching Torah. The Gemara later in Nedarim (דף ס"ב.) records that one of the Tannaim was troubled for his entire life because he had once derived personal benefit from his status as a Torah scholar, and then later cites a proof that one who uses the "crown of Torah" for his own personal gain will be uprooted from this world; the Gemara in Bava Basra (דף ח.) also refers to a certain Talmid Chochom who refused to accept monetary support which was being offered to him simply because of his Torah knowledge. The Rambam, in his Peirush HaMishnayos on the aforementioned Mishnah in Pirkei Avos (שם), goes on at great length to demonstrate that it is improper for one to gain financially from his Torah knowledge, showing how many of the great Tannaim and Amoraim engaged in even menial labor, when possible, and asserting that it is wrong for people who are knowledgeable in Torah to expect to get funds from others simply because they are involved in Torah study. He adds that to take money under such circumstances is a kind of Chillul Hashem, because people will come to think that involvement in Torah is a job like any other, designed just to make a living from, and he concludes by citing the above mentioned Gemara in Nedarim (שם) and in Bava Basra (שם) as definitive proofs to this. Rabbeinu Yonah, in his commentary on the Mishnah in Pirkei Avos (שם בד"ה רבי), states that a person may not benefit financially at all from his Torah knowledge, and he adds (שם בד"ה וכן) that one who is healthy and can work is completely forbidden to benefit from his Torah knowledge. Indeed, an earlier Mishnah in Pirkei Avos (פרק ב' משנה ב') states that in order for one's accomplishments in Torah to have lasting value, one must have some other means of earning a livelihood.
The Rambam (פרק ג' מהל' תלמוד תורה הלכה י') rules that it is forbidden to involve oneself in Torah alone and survive on Tzeddakah, and not do any other work which will enable him to earn a living, and to do this is in fact a Chillul Hashem, and a disgrace to the Torah, because it is prohibited for one to derive benefit from the words of Torah in this world; he then cites some of the sources presented above to back up this view that one must have a means of support for himself other than Torah. The Rambam reiterates this position, albeit in brief, in his Peirush HaMishnayos in Nedarim (פרק ג' משנה ד'), and he rules this way as well elsewhere in his Mishneh Torah (פרק י' מהל' מתנות עניים הלכה י"ח), saying that even a great Talmid Chochom must engage, if necessary, in even a disgusting type of work rather than accept money from others, and he cites examples of Gedolei Yisrael who had menial jobs and refused to accept money offered to them by other people. This position is also quoted by the Tur (יורה דעה סימן רמ"ו); in the Shulchan Aruch, the Ramo (שם סעיף כ"א) writes that one should not plan to become wealthy by being involved in Torah, because one who thinks that he will, will not achieve the crown of Torah, and then he too quotes the position cited by the Rambam (שם) and by the Tur (שם) prohibiting one to derive personal benefit from the Torah. The Maharal, in his commentary entitled Derech Chaim on an earlier Mishnah in Pirkei Avos (פרק א' משנה י'), writes that when Talmidei Chachomim take money from the community, this brings dishonor to the Torah because these Talmidei Chachomim may then be afraid to speak against those who support them, and he asserts that having other work to do actually brings greater honor to the person; he adds in a comment later there (פרק ד' שם) that people who see learned Jews receive money from others conclude that the whole purpose in learning Torah is to benefit from others, which brings down the honor of the Torah. The Keren Orah, commenting on the aforementioned Gemara in Nedarim (שם בד"ה ועפ"ז), writes similarly that many have tried to justify the practice of Talmidei Chachomim benefitting personally from Torah, and none of the leniencies are really solid, which leads Talmidei Chachomim to be disrespected by many people. The Bartenura, commenting on the above cited Mishnah in Bechoros (פרק ד' משנה ו' בד"ה הנוטל), writes strongly that it is improper for a Rav to accept too much money for carrying out certain duties, and his view is cited in the Shulchan Aruch (אבן העזר סימן קנ"ד, סדר הגט סעיף ד'), although the Ramo (שם) disagrees, and the Tosafos Yom Tov, in his commentary on that Mishnah in Bechoros (שם בד"ה הנוטל) elaborates on this issue. But it does seem clear according to these views that one should not derive personal benefit from the Torah.
It must be noted, however, that Rav Yosef Karo writes in his Kessef Mishneh, commenting on the aforementioned Rambam (הל' תלמוד תורה שם), that there is never any actual prohibition to get paid for teaching or learning Torah, and he goes on at great length to refute the proofs, some of which are mentioned above, which seem to indicate that there is such a prohibition. He admits that one may voluntarily decide not to benefit financially from his Torah knowledge, and that one who has some other source of income should not get paid for his involvement in Torah, but he asserts that there is no absolute prohibition against taking money for teaching (or learning) Torah, and he brings several proofs to this idea, concluding that if one has no other source of income, he may indeed get paid to teach Torah, either by the students or by the community, as he notes has been the wide-spread practice for many years. He writes similarly in his Beis Yosef, commenting on the Tur (שם בד"ה ומ"ש דברי), that he disagrees with the above documented view of the Rambam (שם), asserting that most authorities have not accepted this view of the Rambam (שם), and he adds that this dissenting opinion can be solidly defended, and the proofs to the contrary can be refuted, concluding that had people not been able to get paid for teaching Torah, the Torah would have already been lost. He also refers to the opinion of the Tashbatz (שו"ת התשב"ץ חלק א' סימנים קמ"ב-קמ"ח), who discusses this issue at length, analyzing and explaining relevant passages from many different places in the Gemara, and concluding that one may indeed get paid for teaching Torah and leading a community in Torah matters, although that should not be one's motivation for pursuing Torah study, and he asserts that it is in fact obligatory upon the community to properly support their Torah teachers, though as an act of piety, one may refuse to accept such payment. This also seems to be the position of the Bach, in his commentary on the Tur (שם בד"ה ומ"ש כל), as well as of Rav Yaakov Emden, who discusses this issue in great detail in his commentary entitled Lechem Shomayim on the aforementioned Mishnah in Pirkei Avos (פרק ד' שם בד"ה ולא), and of the Yam Shel Shlomo in Chulin (פרק ג' סימן ט'), and of the Shach (שם ס"ק כ'), among others.
The Ramo cited above (יו"ד שם) writes that one who is too old or too sick to earn a living may certainly be supported through the Torah which he learns and teaches, and he thus can derive personal benefit from it; this may be hinted at by a Gemara in Bava Metzia (דף פ"ד:), although the Vilna Gaon (ביאור הגר"א שם ס"ק ס"א) points to a different source. The Ramo (שם) also writes, referring to the Beis Yosef (שם) and to the Tashbatz (שם), that some allow even a normal, healthy person to be supported for his Torah, and he adds, mentioning the Abarbanel, in his commentary entitled Nachalas Avos on that Mishnah in Pirkei Avos (שם בד"ה וכבר), that the custom in all Jewish communities is for the Torah leaders to be provided for by the community in order that they should not have to find some other type of work, which would lead to shaming the Torah. It should be pointed out that the Abarbanel (שם) asserts, as do others, that this leniency developed because there was a fear that if people would not be paid for their involvement in Torah, others would hesitate to get involved in Torah, and a great danger to the Torah's survival would result; he also insists that the money taken by Torah teachers be no more than what is necessary, and that it be provided by the community, not by individuals. The Chasam Sofer too (שו"ת חתם סופר חלק חושן משפט סימן קס"ד) writes that because the Torah will be lost unless people will get paid to be involved in its study, it is permissible today to derive personal benefit from the Torah, and he says as well that the community must hire someone whose job it is to be available for Torah guidance. Rav Moshe Feinstein (שו"ת אגרות משה יו"ד חלק ב' סימן קט"ז) agrees to this position as well, and encourages people to accept whatever rewards are necessary in order to continue to grow and develop in terms of Torah. A full analysis of this subject, including a description of many of the sources cited above, is presented in the Sefer Shaarei Talmud Torah (שער ו' פרק ג'), while a brief synopsis is presented by the Mishnah Berurah, in his Biur Halacha (אורח חיים סימן רל"א בד"ה בכל), who notes that under certain conditions, even the Rambam would agree that one may get paid for one's involvement in Torah.
It should be noted that specifically regarding the teaching of Torah, concerning which we have the above cited rule of מה אני בחנם אף אתם בחנם, the Yerushalmi in Nedarimפרק ד' משנה ג', דף י"ד:( ) distinguishes between different subject matters within the study of Torah, saying that one must teach the laws and the statutes (חוקים ומשפטים) to others for free, but for teaching מקרא, the actual text of the Torah, and its Targum translation, one may get paid; the Yerushalmi (שם) also presents the concept of שכר בטלה, payment for one's time (during which one could have earned money by doing something different), indicating that when teaching children, as explained by the Korban HaEidah (שם בד"ה שכר), one gets paid regardless of the topic because he is giving up time which he could have used to earn money some other way. In the Talmud Bavli, the Gemara in Nedarim (דף ל"ז.) likewise indicates that one may get paid for teaching מקרא; the Gemara שם() suggests two reasons for this. One is that this teacher is really receiving שכר שימור, payment for watching (the children); the Ran (שם בד"ה רב) explains that generally, those who learn מקרא, the text of the Torah, are younger children, who have to be watched in any case, so the teacher's salary here is really for baby-sitting, for which he may certainly get paid. A second reason is that the teacher in this case is also teaching something else which is not included in the requirement to teach Torah for free; it appears that this second view is accepted, as implied by the decision of the Rambam (פרק ו' מהל' נדרים הלכה ז') and of the Shulchan Aruch (יו"ד סימן רכ"א סעיף ב') about the specific case which the Gemara (שם) is addressing, concerning vows. The Ran (שם בד"ה ורבי) spells out the difference between the two views, indicating that according to the second view, one may get paid for teaching מקרא even to an adult, where baby-sitting is obviously not a factor, and he asserts that this is the Halacha. The Ran earlier (שם בד"ה ולענין) adds that although one may not get a salary for teaching anything beyond מקרא, one may still receive שכר בטלה for teaching such things. This concept of paying a Rav שכר בטלה, payment for his time, is presented by the Gemara in Kesubos (דף ק"ה.) which explains that this is why a certain Rav could get paid for judging a particular case, and concludes that the loss of potential wages during the time when one is involved in teaching Torah must be evident and clear. Indeed, the Gemara there (שם) also states that the Torah leaders and Halachic decisors are paid with communal funds, and the Rambam (פרק ד' מהל' שקלים הלכה ז') and the Shulchan Aruch (חו"מ סימן ט' סעיף ג') rule accordingly. Tosafos in Bechoros (שם בד"ה מה) also asserts that the reason that one may get paid today for teaching Torah is that he is really receiving שכר בטלה, and the Shulchan Aruch (שם סימן רמ"ו סעיף ה') states this as well; the Aruch HaShulchan (שם סימן רמ"ה סעיף י"ד) accepts this as the Halacha, and clarifies some details. The Rambam (פרק א' מהל' תלמוד תורה הלכה ז') writes that it is actually customary to hire someone to teach a child Torah SheBiKesav, a practice recorded as well in the Shulchan Aruch (שם סימן רמ"ה סעיף ו', ועיין שם בש"ך ס"ק ה'), where Torah SheB'al Peh subjects are also mentioned; according to Rabbeinu Yonah, in his commentary on this Parsha (דרשות ופירושי רבינו יונה על התורה, ריש פ' במדבר), the practice to financially support those who teach Torah dates back to the time of the Geonim. It is thus clear that one may receive money today for teaching any aspect of Torah, because the salary is really considered שכר בטלה, although the Shulchan Aruch HaRav (הל' תלמוד תורה פרק ד' הלכה ט"ז) says that if one can afford to live without getting paid for teaching Torah, he should certainly do so; it is noteworthy that the Birkei Yosef (או"ח סימן קנ"ה ס"ק א') rules that when one does get paid for teaching Torah, the time he spends teaching does not count in terms of his personal obligation to set aside time for Torah study.