וַיִּשְׁלַ֣ח אֵלָ֣יו מַלְאָכִ֣ים ׀ לֵאמֹר֩ ׀ מַה־לִּ֨י וָלָ֜ךְ מֶ֣לֶךְ יְהוּדָ֗ה לֹא־עָלֶ֨יךָ אַתָּ֤ה הַיּוֹם֙ כִּ֚י אֶל־בֵּ֣ית מִלְחַמְתִּ֔י וֵאלֹהִ֖ים אָמַ֣ר לְבַֽהֲלֵ֑נִי חֲדַל־לְךָ֛ מֵאֱלֹהִ֥ים אֲשֶׁר־עִמִּ֖י וְאַל־יַשְׁחִיתֶֽךָ׃
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; and God hath given command to speed me; forbear thee from meddling with God, who is with me, that He destroy thee not.’
From David to Destruction
Yoshiyahu HaMelech, entirely unnecessarily, enters into battle with Paroh Necho. Paroh Necho, according to the account in Divrei HaYamim II 35:21, even communicates to Yoshiyahu HaMelech that he is merely using Eretz Yisrael as a route to fight the Babylonians at the Battle of Carchemish. According to Chazal (Ta’anit 22b), Yirmiyahu Hanavi warns Yoshiyahu HaMelech against intervening.
Rashi
I will cause the sun to set at midday—When there will be exceeding tranquility, a sudden downfall will come and our Rabbis said: This refers to the day of Josiah who died by the “peaceful sword” as our Rabbis said: There was no more peaceful sword than Pharaoh-Neco who said to Josiah, (II Chron. 35:21) “What do I have to do with you, O king of Judah; not upon you yourself today.” Not upon you do I come today, but to pass through your land “to the house against which I wage war etc.” [from Mo’ed Katan, Ta’anith 22a]