Like his grandfather, Hezekiah, Josiah reforms Judah. He is spared from national defeat, but his sons are not. They rebel against God and pay the price by being defeated by Egypt. Egypt is using Judah as a buffer against Babylon, which is the rising power of the day.
Generations of incomplete obedience to God reduces Judah to a weak nation between superpowers. This was not God’s plan. God’s plan was for Judah to be an example of God’s power throughout the world. Unfortunately, they did not obey Him, and He could not give them success.