The Rambam · Sefer Ahavah
הלכות תפילין ומזוזה וספר תורה ז׳Tefillin, Mezuzah and the Torah Scroll 7
Chapter 7 of 10 in Tefillin, Mezuzah and the Torah Scroll — 16 halachot
Halacha 1א׳
מצות עשה על כל איש ואיש מישראל לכתוב ספר תורה לעצמו שנאמר ועתה כתבו לכם את השירה כלומר כתבו לכם תורה שיש בה שירה זו לפי שאין כותבין את התורה פרשיות פרשיות ואע"פ שהניחו לו אבותיו ספר תורה מצוה לכתוב משלו ואם כתבו בידו הרי הוא כאילו קבלה מהר סיני ואם אינו יודע לכתוב אחרים כותבין לו וכל המגיה ספר תורה ואפילו אות אחת הרי הוא כאילו כתבו כולו.
It is an affirmative precept binding upon every individual Israelite to write a scroll of the Law for his own use, as it is said, "Now therefore write ye this Song for you" (Deuteronomy 31:19). As the Torah is not written in separate sections, this text means, "Write for yourselves the Torah in which this Song is contained." Even if one's ancestors have left a person a scroll, it is a religious duty to write a scroll at his own expense. If he wrote it with his own hand, it is accounted to him as if he had received it from Sinai. If one does not know how to write a scroll, he should get others to write it for him. He who corrects a scroll, even a single letter of it, is regarded as if he had written it completely.
Halacha 2ב׳
והמלך מצוה עליו לכתוב ספר תורה אחד לעצמו לשם המלך יתר על ספר שיהיה לו כשהוא הדיוט שנאמר והיה כשבתו על כסא ממלכתו וכתב לו וגו' ומגיהין אותו מספר העזרה ע"פ בית דין הגדול זה שהיה לו כשהוא הדיוט מניחו בבית גנזיו וזה שכתב או שנכתב לו אחר שמלך יהיה עמו תמיד ואם יצא למלחמה ספר תורה עמו נכנס והוא עמו יושב בדין והוא עמו מיסב והוא כנגדו שנאמר והיתה עמו וקרא בו כל ימי חייו.
A king has the duty of writing for himself another scroll of the Law, in his capacity as sovereign, in addition to the scroll which he owns in his private capacity, as it is said, "And it shall be, when he sitteth upon the throne of his kingdom, that he shall write him a copy of this law, etc." (Deuteronomy 17:18). This copy is corrected by comparison with a scroll kept in the temple court, and under the authority of the Supreme Judicature. The scroll which the king had possessed when he was a private individual, he places in his archives. The one that he wrote or had written for him when he became king, should always be with him. If he goes to war, the scroll is to be with him. When he enters his home, it is to be with him. When he hears a cause (tries a case) it is to be with him. When he sits down to a meal, it is to be placed before him, as it is said, "And it shall be with him, and he shall read therein all the days of his life" (Deuteronomy 17:19).
Halacha 3ג׳
לא היה לו ספר תורה קודם שימלוך צריך לכתוב לו אחר שמלך שני ספרי תורה אחד מניחו בבית גנזיו והשני יהיה עמו תמיד לא יסור מעמו אלא בלילה בלבד וכשיכנס לבית המרחץ או לבית הכסא או לישן על מטתו.
If he possessed no scroll before he came to the throne, he has to write, after his accession, two scrolls of the law, one of which he places in his archives, while the other is to be always with him. It must never be away from him, except at night, or when he goes to the bath or the lavatory or lies down on his couch to sleep.
Mishneh Torah, Hebrew Wikisource edition, via Sefaria — CC BY-SA
English: The Mishneh Torah by Maimonides, tr. Moses Hyamson, 1937-1949 — public domain