The 17th mitzvah is that we are commanded that every king who sits in rulership over the Jewish people shall write a Sefer Torah for himself;1 and that it shall never be separate from him.2

The source of this commandment is G‑d's statement (exalted be He), "And when he is established on his royal throne, he shall write for himself a copy of this Torah."

All the details of this mitzvah have been explained in the second chapter of tractate Sanhedrin.3