Why, asks רב משה פינשטיין, did Hashem have to circumnavigate the Plishtim and change the route of the Jews? He could have just protected them like He did with the Egyptians using clouds to block any harm that might come to them? Rav Moshe answers that, of course Hashem could have made a miracle for them and protected them. Had they trusted Him totally, believed in Him without fearing the physical combat, and knowing that He didn't take them out of Egypt to die in the desert, they could have taken the straight route. However, since He knew that upon seeing a war they would panic because they didn't have the proper trust, they weren't worthy of these miracles & therefore had to go roundabout through the desert.
The Torah tells us that a short time later Pharaoh came back with his army to chase them & then Hashem did protect them from all harm. How was it that such a short time later they had become worthy & obviously had the proper trust in Hashem?
The Chafetz Chaim explains that when Hashem took the Jews out of Egypt, He had two ways to lead them: either through the desert or through the land of the Pilishtim. On the one hand, the land of the Plishtim was inhabited so there would be food & provisions for all the people. On the other hand, though, they were an idolatrous nation who could have influenced the Jews who were just coming up out of their impure state. The other choice was the way of the desert where there were no provisions, no food and no water for millions of people. On the positive side, though, there were no impure people either that could negatively influence the Jews.
Hashem chose the route He felt would be more beneficial for the Jews spiritually & therefore took them the route of the desert even though there would be no food.
The Chafetz Chaim says that this demonstrates that one who is thinking about starting a career which is contrary to halacha should not say, “What could I do; I have to make a living. Rather he should realize that Hashem took millions of people through the desert with no provisions & was able to provide for them; so, too, He could provide whatever is necessary without without you putting yourself in a situation that would negatively influence you.
We could add to the Chafetz Chaim’s interpretation & recognize that Hashem took the Jews via the indirect way through the desert, deliberately bringing them to a place with no provisions when He could have brought them through civilized land. This showed them that He would take care of them no matter what, which in itself instilled in them the absolute trust in Hashem that they displayed by the Egyptians. This trust warranted Hashem’s performing all the miracles to save them from the hands of the Egyptians, first by blocking the Egyptians’ arrows with the clouds & later drowning them at sea. This shows us that all we have to do is have absolute trust in Hashem & then He will do the rest!