In this post, I'll share a quote by Karel Van Der Toorn's on canonization in Scribal Culture and the Making of the Hebrew Bible. On page 263, Van Der Toorn states what he believes led to canonization of the Hebrew Bible:
"The canon of the Hebrew scriptures has come about on account of two decisions carried out by persons or institutions in a position of authority. One decision was the promulgation of the Torah as the law of the land, issued by God, legitimized by the king, and enforced by Ezra and Nehemiah; the political motive behind this decree is unmistakable. The second act of authority, occurring about two centuries later, was the enunciation of the dogma of the prophetic era. The edge of the doctrine lay in the rejection of claims of inspiration by people in the post-prophetic era. The scribal establishment of Jerusalem attempted to secure its moral leadership by disqualifying contemporary visionaries and ecstatics as empty chatterboxes; the real prophets were the Books of the Prophets, to whose interpretation the scribes held the keys."
So there was a desire to make the Torah the law of the land, as well as to limit prophecy. Another factor that Van Der Toorn discusses is Hellenism. In response to the "Hellenization of the Near East", there were national histories that were produced, such as the Babylonian priest Berossus' third century B.C.E. history of Mesopotamia, and Manetho's second century B.C.E. history of Egypt. According to Van Der Toorn, "The publication of the Prophets, the Psalms, and the Proverbs by the temple scribes of Jerusalem can be viewed as a Jewish response to the cultural impact of Hellenism" (page 259).
I'd like to make one more point. Why did Ezra and Nehemiah promulgate the Torah as the law of the land? According to Van Der Toorn, the Persians sought to solidify their rule by sanctioning the laws of their subject nations, and, if a nation did not have a national law, the Persians encouraged it to create one. The Demotic Chronicle, for example, states that King Darius of Persia "ordered the governor of Egypt in 518 to install a commission of priests, scholars, and military leaders to put the laws of Egypt into a military code", and Darius sent an Egyptian priest named Udjahorresnet from Elam "to restore the workshops of the Egyptian temples, thereby creating the necessary infrastructure for the implementation of the law" (page 249). This Egyptian priest was like Ezra, whom the Persians sent to Israel to help implement the Torah as the law of Yehud.