It sure seems like he did. See this passage:
After Josiah had done all this for the temple, King Necho of Egypt marched up to do battle at Carchemish on the Euphrates River. Josiah marched out to oppose him. Necho sent messengers to him, saying, “Why are you opposing me, O king of Judah? I am not attacking you today, but the kingdom with which I am at war. God told me to hurry. Stop opposing God, who is with me, or else he will destroy you.” But Josiah did not turn back from him; he disguised himself for battle. He did not take seriously the words of Necho which he had received from God; he went to fight him in the Plain of Megiddo. 2 Chron 35.20-22
It’s not terribly unusual for God to speak to pagans, even foreign kings. But this is a twist: a foreign king speaking the word of God to a king of Judah. One supposes that if God can make a donkey can speak to a prophet, he can make a pagan king speak to his anointed one.
It could have been through a dream. Apparently, the Chronicler has Spirit inspiration behind him to confirm that it was God who spoke to Necho. But how would Josiah have figured that out? What expectation would he have that this pagan ruler was actually bringing him a revelation from God? It’s a passage that puzzles me.
Got any perspectives on it?