Exodus 14:2

Speak unto the children of Israel, that they turn and encamp before Pi-hahiroth, between Migdol and the sea, over against Baal-zephon: before it shall ye encamp by the sea.

The command was to turn back from the line of march and encamp by the sea, beside the Red Sea, leaving the direct course to enter a rocky defile. The appointed spot was named as Pi-hahiroth, between Migdol and the sea, over against Baal-zephon, with the camp to be made before it by the sea. That place was not chosen by human judgment but picked by God Himself, who deliberately directed Moses just where to encamp.

God knew beforehand what would follow there and told Moses in advance that Pharaoh would pursue Israel to that place, and that He would be honored before Pharaoh and all his host through their deliverance. The order to camp by the sea belonged to His larger leading of Israel by the way of the sea instead of by the near road through the land of the Philistines. The Philistines would have opposed their passing as fugitives and runaways stolen from their masters in Egypt, and would have made war with them. Meeting war on that near road would have caused Israel to turn back to Egypt. By bringing them the sea way instead, He showed Himself compassionate as well as a God of judgment.

After the Hebrews had been gone some days, the Egyptians understood they had fled never to return to service, mourned the great loss of their labor, and regretted letting them go. Though hardened by continual rebellion after all they had suffered under God's judgments, they resolved to bring them back by force into Egypt, so the king took a very large army with six hundred chariots and overtook them while they were encamped by the sea. The divinely chosen ground thus left Israel in a position that looked like a trap, hemmed in by mountains with Pharaoh's army pursuing from behind, facing danger with the way apparently blocked.

The people concluded they had been led onto the wrong course, and their fear and blaming of Moses laid bare rebellious, discouraged hearts. Moses, by contrast, had followed God's command and direction in faith and did not fear the danger, because he trusted God to provide deliverance. The whole setting was a test of Israel's trust, preparing the way for God to deliver them and rid them of their enemies.