Shemot / Exodus 13:17 · Pshat
וַיְהִי בְּשַׁלַּח פַּרְעֹה אֶת־הָעָם וְלֹא־נָחָם אֱלֹהִים דֶּרֶךְ אֶרֶץ פְּלִשְׁתִּים כִּי קָרוֹב הוּא כִּי אָמַר אֱלֹהִים פֶּן־יִנָּחֵם הָעָם בִּרְאֹתָם מִלְחָמָה וְשָׁבוּ מִצְרָיְמָה׃
And it came to pass, when Pharaoh let the people go, that the Almighty did not lead them by the way of the land of the Plishtim (Philistines), although it was near, for the Almighty said: "Lest the people change their minds when they see war, and return to Egypt."
Pshat פְּשָׁט
The short road is not the best one
The navigator shows the shortest route, but an experienced driver sometimes takes the detour. A short road can bring you to the place where you give up and turn back. The Torah explains why Israel were led the long way.
Rashi: "did not lead" means "did not guide". The road through the land of the Plishtim was near, and it was just as easy to go back by it to Egypt. Seeing war, the people would have turned back: even on the roundabout road they said "let us return to Egypt". Rashbam: it was the straight road into the land of Kenaan, and the wars there would have broken the people.
How Rashi and Rashbam explain it
Rashi And it came to pass, when Pharaoh let the people go, that He did not lead them
He did not guide them, as it says: "go, lead the people" (Shemot / Exodus 32:34), and as it says: "when you walk, it shall lead you" (Mishlei / Proverbs 6:22).
Rashi Although it was near
And it is easy to return to Egypt by that same road. And there are many stories and interpretations of the sages about it.
Rashi When they see war
For example, the war of which it says: "and the Amalekites and the Kenaani came down" and so on (Bamidbar / Numbers 14:45). If they had gone by a straight road, they would have returned. For even when He led them around, by a crooked road, they said: "Let us appoint a head and return to Egypt" (Bamidbar / Numbers 14:4). If He had led them by the straight road, all the more so.
Rashi Lest they change their minds
Lest they think again about having left, and set their hearts on returning.
Rashbam By the way of the land of the Plishtim (Philistines), although it was near
It is the straight road, to enter the land of Kenaan (Canaan) at once. And when they came to the hardship of the wars in the land of Kenaan, they would have appointed a head and returned to Egypt, as they did several times. As it is written: "Would it not be better for us to return to Egypt?", "Let us appoint a head and return to Egypt", "We remember the fish which we ate in Egypt".
Takeaway
"Did not lead" (נָחָם) comes from the verb "to lead" (נָחָה), and "lest they change their minds" (יִנָּחֵם) from the verb "to change one's mind, to regret" (נִחַם). The words sound alike, and Rashi explains that the first means "guided".
The war in Rashi's example: after the spies' report the people went up without Moshe (Moses), and the Amalekites and the Kenaani struck them "as far as Chormah" (Bamidbar / Numbers 14:44–45).
The words Rashbam quotes stand in Bamidbar / Numbers 14:3, 14:4 and 11:5.