And now, write for yourselves this song and teach it to the Children of Israel. Place it into their mouths, in order that this song will be for Me as a witness for the children of Israel. (Deuteronomy 31:19)
The Gemara cites this verse as the source for the last commandment in the Torah while rules that it is incumbent on every Jewish male to write their own sefer Torah (Sanhedrin 21b). Maimonides (d. 1204) emphasises that this commandment is a personal obligation which applies even if someone inherits a sefer Torah from their parents.
The Gemara (Menachos 30a) also states that someone who buys a sefer Torah is like one who ‘grabs a mitzvah from the marketplace’, implying that one must create new sifrei Torah, not merely acquire an existent one. Nevertheless, the Gemara (ibid.) also notes that since a sefer Torah must be written without any mistakes, when someone corrects a single letter it is as if he has written the entire sefer Torah.
The custom of commissioning a sefer Torah for the sake of the community probably grew from this mitzvah. The donor not only has the opportunity to complete the final letters of the Torah thereby performing the mitzvah itself, but also fulfils the higher purpose of the mitzvah by increasing the use of the sefer Torah.
Rabbeinu Asher (d. 1327) quoted in the Shach (Yoreh Deah 270:5) writes that the primary purpose of writing a personal sefer Torah was to facilitate Torah learning which is also implied by the latter part of our verse. Nowadays since people do not learn directly from a sefer Torah but rather learn from printed books, Rabbeinu Asher wrote that the mitzvah may apparently be fulfilled by purchasing printed texts such as a Chumash, Mishnah and Talmud. Others contend that Rabbeinu Asher is merely adding to the mitzvah of writing a sefer Torah, but not replacing it.
Either way, the essence of this mitzvah demonstrates the importance of helping to build and maintain the infrastructure for Jewish education. It is not the physical scroll but rather the study of Torah which bears witness to God and His eternal covenant for the generations to come.