Exodus 14:4
And I will harden Pharaoh’s heart, that he shall follow after them; and I will be honoured upon Pharaoh, and upon all his host; that the Egyptians may know that I am the LORD. And they did so. And I will harden Pharaoh’s heart, that he shall follow after them; and I will be honoured upon Pharaoh, and upon all his host; that the Egyptians may know that I am the LORD. And they did so.
God directed Israel to a specific camping place before the sea, a position that appeared trapped and dangerous, knowing beforehand that Pharaoh would conclude they were entangled and decide to pursue them. He told Moses in advance exactly where to encamp in order to bring this about, announcing that he would harden Pharaoh's heart so that Pharaoh and all his host would follow after Israel. Moses therefore placed Israel in that danger in faithful obedience to God's direction, not by misleading them.
God led Israel by the way of the sea rather than by the near way through the land of the Philistines because the Philistines would have opposed them as fugitives from their masters and made war with them, and Israel would have repented at the sight of war and turned back to Egypt. In this leading he revealed himself as compassionate as well as a God of judgment.
After Israel had been gone some days, the Egyptians were told they had fled never to serve again, felt the loss of their service as very great, and regretted letting them go. Though they had suffered under God's judgments, hardened by continual rebellion they resolved to bring Israel back to Egypt by force. Pharaoh therefore pursued with a very large army with six hundred chariots and overtook Israel while encamped by the sea.
Through what happened to Pharaoh and his army in Israel's deliverance God would be honored and reveal his power, so that the Egyptians would know that he is the Lord. The apparent danger was part of the situation in which God would act to reveal his power and prove it superior to every other. That pursuit became the final display of God's power and justice before the Egyptians, making his name known in Pharaoh's last rebellion and the destruction of the Egyptian host. This judgment followed God's merciful deliverance of Israel and was meant to strengthen Israel's faith and lead its descendants to worship him alone. Israel's fear and complaints at the sea came from their own rebellious hearts, not from being misled.