"…Josiah's kingdom was actually rather puny, and his purpose in having the Deuteronomistic History written was to unite the various warring Israelite tribes into a single powerful empire under his rule. That would be why the king's scribes write that Israel and Judah were once united under David and Solomon (Josiah’s ancestors – thereby establishing precedent); that is why the people of Israel are said to have been once united as one during the time of Joshua; that is why the covenant says that all should worship in one temple, conveniently located in Josiah’s capital (Jerusalem – again, giving him control)…"
Ha'aretz has a new article explaining the predominant scholarly understanding of who wrote large parts of Tanakh and why some of those parts were written. (This is all based on loads of evidence, by the way, including almost 200 years of scholarly analysis, at least one computer algorithm analysis that validates it, and lots of archaeological research, although Ha'aretz doesn't cite most of it.) Here's an excerpt:
…The [biblical] narrative repeatedly tells how the people of Israel defied the divine will, were punished, and submitted to a forgiving God.
This all leads up to the reign of King Josiah [Yoshiyahu].
It is during his reign (641–609 BCE) that an early form of the Book of Deuteronomy, with the long-lost covenant made between God and Israel, was supposedly discovered lying around in the Temple.
This Book became the basis of a series of reforms, which made Josiah, according to his own scribes, the best king ever: “Now before him there was no king like him, who turned to the Lord with all his heart, with all his soul, and with all his might, according to all the Law of Moses; nor after him did any arise like him” (2 Kings 23:25).
It starts to seem that the Deuteronomistic History was written during the reign of King Josiah. The whole story seems to lead up to his reign, and he is portrayed very favorably in it.
If this is indeed true, and most scholars think it is, Josiah's kingdom was actually rather puny, and his purpose in having the Deuteronomistic History written was to unite the various warring Israelite tribes into a single powerful empire under his rule.
That would be why the king's scribes write that Israel and Judah were once united under David and Solomon (Josiah’s ancestors – thereby establishing precedent); that is why the people of Israel are said to have been once united as one during the time of Joshua; that is why the covenant says that all should worship in one temple, conveniently located in Josiah’s capital (Jerusalem – again, giving him control); and that is why they took the trouble to stitch together the different stories, legends and myths of the different people of the land (sometimes conflicting stories) into one great story.
All this was an attempt to bolster a new imperial ideology - one people worshiping one God in one temple under one king.
But this would fail miserably.…The years that followed did not do well by Judah, and eventually the little kingdom was destroyed by Josiah’s own allies - the Babylonians. The Judean elite was exiled to Babylon. But they took along their ancient texts, including the Deuteronomistic History.
It was there in Babylon that another scribe wrote a brief account of the events after Josiah’s [battlefield] death, and tacked it to the end of the book.…
[T]he Deuteronomistic History was mostly written in the court of King Josiah, who hoped to forge a great Israelite empire under his command, but who died [in battle] before it could come to be.