Question: In 2 Kg.22:20 God promises Josiah that he will have a peaceful death. But Josiah's death was anything but peaceful. (2 Kg.23:29-30, 2 Chr.35:23-24)
Response: A second look at 2 Kings 22:20 shows that Josiah is not being promised a peaceful death, but rather a peaceful burial:
"Surely, therefore, I will gather you to your fathers, and you shall be gathered to your grave in peace; and your eyes shall not see all the calamity which I will bring on this place." So they brought back word to the king. (2 Kings 22:18-20 NKJV, emphasis added).
Most of the English versions that I have seen use a wording that is similar or identical to the NKJV's you shall be gathered to your grave in peace phrasing. The NIV more clearly makes the distinction between the nature of one's death and the nature of one's burial by rendering 2 Kings 22:20 in this way:
"Therefore I will gather you to your fathers, and you will be buried in peace. Your eyes will not see all the disaster I am going to bring on this place." So they took her answer back to the king. (2 Kings 22:18-20 NIV, emphasis added).
The promise is not that Josiah would die in peace. Rather, the promise involved the conditions under which Josiah would be buried, or "gathered into thy grave". A key to understanding the nature of this promise to Josiah is in the phrase that ends the verse: and thine eyes shall not see all the evil which I will bring upon this place. It is this last phrase that explains the nature of the promise to Josiah - that he would be buried before the destruction of Judah that was about to take place. And that promise was fulfilled.