King Josiah was undoubtedly a saved man, a true child of God. He was going to heaven to be with God after his death. God promised this in fairly plain language.
“And as for the king of Judah, who sent you to enquire of the LORD, so shall ye say unto him, Thus saith the LORD God of Israel [concerning] the words which thou hast heard; Because thine heart was tender, and thou didst humble thyself before God, when thou heardest his words against this place, and against the inhabitants thereof, and humbledst thyself before me, and didst rend thy clothes, and weep before me; I have even heard [thee] also, saith the LORD. Behold, I will gather thee to thy fathers, and thou shalt be gathered to thy grave in peace, neither shall thine eyes see all the evil that I will bring upon this place, and upon the inhabitants of the same. So they brought the king word again.” (2 Chronicles 34:26-28 AV)
Yet, we see a dichotomy in this Godly man at the end of his life.
“After all this, when Josiah had prepared the temple, Necho king of Egypt came up to fight against Carchemish by Euphrates: and Josiah went out against him. But he sent ambassadors to him, saying, What have I to do with thee, thou king of Judah? [I come] not against thee this day, but against the house wherewith I have war: for God commanded me to make haste: forbear thee from [meddling with] God, who [is] with me, that he destroy thee not. Nevertheless Josiah would not turn his face from him, but disguised himself, that he might fight with him, and hearkened not unto the words of Necho from the mouth of God, and came to fight in the valley of Megiddo. And the archers shot at king Josiah; and the king said to his servants, Have me away; for I am sore wounded. His servants therefore took him out of that chariot, and put him in the second chariot that he had; and they brought him to Jerusalem, and he died, and was buried in [one of] the sepulchres of his fathers. And all Judah and Jerusalem mourned for Josiah.” (2 Chronicles 35:20-24 AV)
Josiah disobeyed a direct command. The above passage clearly states that the warning of the Egyptian king was from the mouth of God, and yet we see that God had promised him that he would go into his grave in peace. Certainly, Josiah's death was not peaceful, but God couldn't have been referring to this in His promise. There were no conditions for future behavior attached to His promise. God told Josiah that he would go to his grave in peace, which must have meant that he would go to heaven, given the awful, far-from-peace, doubtlessly painful, and bloody process by which the king died. Josiah was killed in a battle he had no business waging because he didn't believe that God would speak through a mere Egyptian. Many patterns in the Bible exhibit God's methodology to be the opposite of what even the most spiritually learned true believer expects. This is a stern warning to those in positions of high influence and those who choose to place themselves under that influence.
“And he said unto them, Ye are they which justify yourselves before men; but God knoweth your hearts: for that which is highly esteemed among men is abomination in the sight of God.” (Luke 16:15 AV)
I don't mean to lump true believers in with hypocrites, but God gives us several examples in the Bible to teach us that even the most Godly men can mess up badly, and God doesn't let them get away with it. David had an illicit affair with another man's wife and then arranged for him to be killed in battle. Solomon let his wives influence him to worship idols. Hezekiah became too proud and ended up blabbing way too much information to an enemy kingdom. Josiah wouldn't listen to God because he was too proud to consider that God can speak through anyone in the whole world. This is especially true now that God's Word is all in one book, and no one has a monopoly on correct Biblical interpretation of the Bible. There but for the grace of God go we all.
“My brethren, be not many masters, knowing that we shall receive the greater condemnation.” (James 3:1 AV)