In chapter 23 we see that the good and righteous king Josiah did everything possible to thoroughly remove every unclean and unholy and idolatrous item from the land. He went to great lengths to be sure there was nothing left or that could ever be recovered that was against the Law of God.
Note that Josiah did this after God had declared through the prophetess Huldah that He would bring disaster upon this place and upon its inhabitants because they had forsaken Him and had made offerings to other gods. And God said, “…therefore my wrath will be kindled against this place, and it will not be quenched.”
It is to Josiah’s credit that he still went forth with his reforms. He could have given up, and just waited for God to bring His judgment. But he didn’t. And sure enough, disaster did come upon them, but only after Pharaoh Neco king of Egypt killed him in battle.
So let’s look at this. Josiah cleaned the place up, and he brought God’s Law back to Judah. Why didn’t God turn from His wrath?
I believe that it is because God looks at the heart, not just the actions. Remember the Sermon on the Mount? Jesus said that if you have thought of doing an unrighteous act, you have done the act. (Rough paraphrase.) God looked at the hearts of the people of Judah. Even though Josiah (whose heart was right) made the people follow the Law through his authority as king, they still longed after those ungodly and idolatrous things they used to do. Outwardly, they did right. But inwardly, they had not changed.
One more thing. Did you know that death is not the worst thing that can happen to you? With the death of Josiah by Pharaoh Neco, God spared Josiah from seeing what was coming down on Judah. It was a merciful act on God’s part. It was not a judgment against him.