If you read the chapter 23 of the book of 1 Kings, you will note that Josiah was one of best kings of Judah. He did many good things in favor to Yahweh-worshipping. Let's read:
And Josi′ah took away all the abominations from all the territory that belonged to the people of Israel, and made all who were in Israel serve the Lord their God. All his days they did not turn away from following the Lord the God of their fathers. (2 Chronicles 34:33)
However, something happened and Josiah died because he fought against an ally of God:
20 After all this, when Josi′ah had prepared the temple, Neco king of Egypt went up to fight at Car′chemish on the Euphra′tes and Josi′ah went out against him. 21 But he sent envoys to him, saying, “What have we to do with each other, king of Judah? I am not coming against you this day, but against the house with which I am at war; and God has commanded me to make haste. Cease opposing God, who is with me, lest he destroy you.” 22 Nevertheless Josi′ah would not turn away from him, but disguised himself in order to fight with him. He did not listen to the words of Neco from the mouth of God, but joined battle in the plain of Megid′do. 23 And the archers shot King Josi′ah; and the king said to his servants, “Take me away, for I am badly wounded.” 24 So his servants took him out of the chariot and carried him in his second chariot and brought him to Jerusalem. And he died, and was buried in the tombs of his fathers. All Judah and Jerusalem mourned for Josi′ah. 25 Jeremiah also uttered a lament for Josi′ah; and all the singing men and singing women have spoken of Josi′ah in their laments to this day. (2 Chronicles 35:20-25)
As we read, Pharaoh Neco decided to go to Carchemish to fight against Babylon as an ally of Assyria, but Josiah tried to impede the intentions of Neco, then Josiah was killed by Neco, who was backed by God. .....I can't understand it. If Josiah was a faithful follower of God, who was representing God's organization on earth, why did God support Neco, instead of His faithful king??
Furthermore, if God supported Neco, God was supporting Assyria against Babylon. But some years later, God supported Babylon against Jerusalem and other cities. Accordingly, the Bible here shows a God who is politically capricious. Doesn't it represent a moral problem for the Bible believers?