According to the tradition of the Gemorah (Gittin 60a), towards the end of this week's parsha (Shemos 34:27) Hashem told Moshe Rabbeinu that he is giving the Jewish people a Torah Shebichsav and a Torah Shebaal Peh, and the covenant with the Jewish people will be based on the Torah Shebaal Peh. When Yehoshua Bin Nun led the Jewish people into Eretz Yisroel, Hashem instructed him to make the written Torah available for all the nations of the world in different languages. The Torah Shebaal Peh, however, is not supposed to be available to others; it is only for the Jewish people. The same possuk also implies that the written Torah should not be recited from memory, rather it should only be read from a sefer. Similarly, the oral Torah may not be read from a sefer and must be recited by heart.
The baalei haTosafos (Temurah 14b) raise the question that our practice often seems to go against this halacha; we recite many passages from the chumash by heart. For example, we recite Shema, Oz Yoshir, and Vayichulu by heart. Tosafos explains that this halacha only applies to a ba'al koreh, who may not recite kerias haTorah by heart when he is reading on behalf of the tzibbur. Based on this interpretation of the Tosafos, the students of the Vilna Gaon (quoted in the sefer Shulchan Hakriya) said that if the person reciting the haftorah is reading from a printed chumash and not from a klaf which contains the entire sefer from which the haftorah is taken, then the congregants in the shul should say the haftorah along with him. Reading from a printed Tanach is considered baal peh and one may not be motzi others with a keriya baal peh. The same is true regarding writing down the Torah Shebaal Peh. The Rambam writes in the introduction to his commentary on Mishnayos that in every generation the chachomim would write "megilas setorim", private notes of halachos of the Torah Shebaal Peh, to make sure that they don't forget them. The halacha derived from the possuk at the end of this week's parsha means that when a rebbe is giving a shiur and transmitting Torah Shebaal Peh to others, the shiur should not be based on reading a text, rather it should be delivered orally.
The Gemorah says that nowadays we are all in violation of this halacha. It is generally assumed that the Mishnayos were written down in the days of Ravina and Rav Ashi and from that time on were no longer recited orally but were taught by reading from a text. Many years later, during the period of the gaonim, the Gemorah was written down and from that time on Gemorah has been taught by reading from a text. The Gemorah (Temurah 14B) bases this practice on the possuk (Tehillim 119) that we are permitted to violate the Torah if we do it lesheim Shomayim. The Mishna (Brochos 54a) has several other heterim based on the same possuk in Tehillim, and Rashi there explains that the possuk does not mean to say that one can outright violate a din of the Torah, rather it merely means that we permit one to do something that appears to be prohibited.
In very rare instances we recommend that one violate the laws of the Torah based on a different principle, not derived from this possuk, which is referred to as chatei bishvil shetizke, roughly translated as, "the ends justify the means". Every legal system provides for such a clause in rare instances. For example: if a woman is in labor at three o'clock in the morning, the police will encourage her husband to drive through the red lights to get to the hospital. Or, if the woman is having a baby on Shabbos, the halacha will permit her husband to drive her to the hospital on Shabbos. However, we would not permit one to steal from others in order to support a yeshiva. The permissibility of a given act depends on which end will be achieved and which means will be used to achieve it.
How can we understand that the teaching of the Mishnayos in the Gemorah from a written text is merely something that appears to be prohibited? Isn't it something that is outright against the halacha? Rav Ovadia Yosef (in his teshuvos) quotes the following explanation from the Sefer Yereiyim: The Chachomim never meant to say that one is violating an aveira if he teaches Torah Shebaal Peh to others from a written text. Rather the Chachomim were saying that the mitzvah beshleimusa of teaching Torah to others can only be fulfilled if you teach it orally. If one transmits Torah Shebaal Peh from a text he is only fulfilling the mitzvah in an incomplete manner. So when the Chachomim recorded the Mishnayos and the Gemorah to serve as the text for the later generations, no aveira was violated but it is only that we are fulfilling the mitzvah of talmud Torah shelo beshleimusa.