Deuteronomy 17:18
And it shall be, when he sitteth upon the throne of his kingdom, that he shall write him a copy of this law in a book out of that which is before the priests the Levites: And it shall be, when he sitteth upon the throne of his kingdom, that he shall write him a copy of this law in a book out of that which is before the priests the Levites:
When seated upon the throne of his kingdom, the king was to write for himself a copy of the law in a book from the text that was before the priests the Levites. That direction was given through Moses long before Solomon became king to guard Israel's rulers against the dangers of kingship and apostasy. He was to keep that copy with him, beside him on his throne, and read in it all the days of his life. Keeping the Word beside him makes a ruler immovable, as David was while he obeyed.
By that continual study he was to learn reverence and fear for God and to keep and do all the words of the law, its statutes, commandments, judgments, and testimonies. The study was meant to keep his heart from being lifted up above his brethren and to keep him from turning aside from the commandment to the right hand or to the left. Obedience on these terms prolongs his days in his kingdom, he and his children in the midst of Israel. For Solomon prosperity and establishment on David's throne was made conditional on walking in God's ways and keeping what was written in the law of Moses.
The surrounding instruction warns the king against accumulating horses, wives, and great wealth, since multiplying wives could turn his heart from God. The law of kingship places the king under God's law rather than as an unchecked monarch. Israel's demand for a king departed from God's direct leadership, and a proud king could lead the people away from God and therefore needed to trust God and receive wisdom from Him.
A monarchical government was foretold, but monarchy was not God's will for Israel. When the people refused His wiser counsel He permitted them to take their own course and instructed Samuel to grant their request while warning of the consequences. God foresaw Israel would desire a king but did not consent to a change in the principles on which the state was founded. God was still recognized as head of the nation, His law was enforced as the supreme law of the land, and the king was to serve as vicegerent of the Most High, administering government in God's name and by His authority with no authority to legislate for the nation, which remained the condition of Israel's existence as a nation.
God reserved to Himself the right to choose the king, and Israel respected that authority by leaving the selection entirely to God, so that the choice fell upon Saul, a son of Kish of the tribe of Benjamin. Solomon knew these instructions and for a time obeyed them, desiring to rule by the statutes given at Sinai in contrast with rulers who trampled God's law. But his later reliance on his own strength and alliances with surrounding nations marked a departure from God's commands. Josiah followed the instruction given for rulers to obey the law for their guidance, and his obedience made him fit for God's service.
When David forsook its doctrines he sullied one of the fairest reputations. Forsaking its doctrines violates the will of God, sets aside God's wisdom for the wisdom of man and human invention, and brings a day of retribution upon nations and individuals.