Great question! I too have pondered this seeming contradiction. What’s clear in the narratives is that Josiah himself experienced genuine brokenness and revival, and God acknowledged this fact regarding him (2 Kings 22:11ff). The king removed abominations and idols and reintroduced observance of the passover (2 Kings 22-23; 1 Chron. 34-35). The people also complied with all that the king commanded—but apparently, not from the heart. Jeremiah 3:10 points out, “And yet for all this her treacherous sister Judah hath not turned unto me with her whole heart, but feignedly, saith the LORD.” The word feignedly means in pretense.
In revival history I have come across pretense that was exposed, but never to this magnitude. During the Manchurian Revival as depicted in By My Spirit, Jonathan Goforth tells the story of a moving of the Spirit. In the midst of the revival, they had great corporate prayer times that were full of life. Yet when one particular man prayed, the atmosphere went dead. He would pray at length and each time the moving of the Spirit was quenched. Goforth thought it wise to wait a few days to be sure he was not overreacting, but still sensing the man was off, he confronted him during a subsequent meeting. The man rose to pray, the previously charged atmosphere was dampened once more, and Goforth plainly told the man to sit down because he was praying in the flesh. Perhaps surprisingly, the man responded by thanking Goforth. He admitted that he sensed what was occurring and had wanted to appear to be part of it. He came clean and admitted his pretense.
In the case of Josiah and Judah, I suppose the lesson here is for leaders to be cautious about using forceful tactics when acting upon good desires. The Spirit must move for there to be a genuine response among followers.