Background
As we meet Jeremiah at the beginning of his prophecies, he is in the midst of puzzling out the punishments coming upon Judah in his day, and YHWH gradually unveils for him many various ways in which Judah was in stubborn rebellion. Despite YHWH's call upon Jeremiah to be a 'fortified city, an iron pillar, and bronze walls' (1:18), at first he does not really seem to understand exactly why.
On three occasions Jeremiah tries crying out to YHWH to intercede for Jerusalem and asking him to relent, but each time is rebuked (Jeremiah 7:16, 11:14, 14:11) and shown yet more of Judah's rebellion until he truly understands the depth of their sin and the necessity of YHWH's judgement. From chapter 14 onwards he stands firm in his calling to stand against Judah's rebellion.
I recall these facts as background not so much because of their relevance to Egypt, but rather to explain that Jeremiah himself does not begin in a place of sound knowledge about the why behind many of his judgements, and rather appears to be led by the pronouncements of YHWH in understanding the current flow of events. So if we want to understand his rationale for these pronouncements, that's where we need to begin.
How Judah's behaviour is framed (Jeremiah 2)
The setup for this entire journey is found in the second chapter of Jeremiah, which frames the whole narrative of YHWH's relationship with Judah:
2 Thus says the Lord, “I remember the devotion of your youth,
your love as a bride, how you followed me in the wilderness,
in a land not sown. 3 Israel was holy to the Lord,
the firstfruits of his harvest. All who ate of it incurred guilt;
disaster came upon them, declares the Lord.”
4 Hear the word of the Lord, O house of Jacob, and all the clans of
the house of Israel. 5 Thus says the Lord:
“What wrong did your fathers find in me
that they went far from me, and went after worthlessness, and became worthless? 6 They did not say, ‘Where is the Lord
who brought us up from the land of Egypt, who led us in the wilderness,
in a land of deserts and pits, in a land of drought and deep darkness,
in a land that none passes through,
where no man dwells?’
The context of Judah's judgement is that she was rescued from Egypt in the first place by YHWH, and that He has been a faithful husband to her through all manner of sin and rebellion. Indeed, Judah now flits back and forth between Egypt and Assyria as her preferred lovers, to whom she looks for salvation.
13 for my people have committed two evils: they have forsaken me,
the fountain of living waters, and hewed out cisterns for themselves,
broken cisterns that can hold no water.
14 “Is Israel a slave? Is he a homeborn servant?
Why then has he become a prey? 15 The lions have roared against him;
they have roared loudly. They have made his land a waste;
his cities are in ruins, without inhabitant. 16 Moreover, the men of Memphis and Tahpanhes
have shaved the crown of your head. 17 Have you not brought this upon yourself
by forsaking the Lord your God,
when he led you in the way? 18 And now what do you gain by going to Egypt
to drink the waters of the Nile? Or what do you gain by going to Assyria
to drink the waters of the Euphrates?
Ultimately, this was all to Judah's shame, and would end in disaster:
36 How much you go about, changing your way! You shall be put to shame by
Egypt as you were put to shame by Assyria.
As the text progresses, YHWH and Jeremiah would remind the people again and again how Judah was saved out of Egypt (7:22, 11:4, 11:7, 24:8) - Egypt is an adulterous lover and an oppressor, not a saviour. This builds on the prophecies of Isaiah, who affirmed the same view:
Behold, you are trusting in Egypt, that broken reed of a staff, which
will pierce the hand of any man who leans on it. Such is Pharaoh king
of Egypt to all who trust in him. (Isaiah 36:6)
Why is Jeremiah opposed to Jewish settlement in Egypt?
Judah had clearly gotten themselves into a real mess, and as we read through the Tanakh one of the recurrent issues is that the people have forgotten what YHWH has done for them, and so this is rediscovered repeatedly from generation to generation. Jeremiah himself appears to have rediscovered much of this during his ministry as well.
YHWH himself supplies the frame for Jeremiah's ministry, set firmly in the historic context of the Exodus - YHWH rescued the people from Egypt, has been faithful to them, and they should trust in Him alone. Jeremiah has been re-educating the people on this matter repeatedly, and reinforcing the message that they were saved out of Egypt, and YHWH alone is their hope: do not rely on Egypt or Assyria for salvation.
In Chapter 25 Jeremiah lays out that YHWH's judgement (and plan) is for the people to go into Babylon, the chosen instrument of his justice in this moment. Moreover, Jeremiah witnesses the cup of YHWH's wrath (25:15), which each of the nations would drink in turn. Immediately after Jerusalem's devastation, Egypt was next in line for judgement - the people fleeing to Egypt would fall under judgement twice, whereas those going to Babylon would return to Jerusalem before Babylon itself fell.
So besides the ideological concerns around Judah going to its other lovers for safety, Jeremiah was also uniquely aware of the judgement that would fall on all who went to Egypt for refuge - and was also suitably unimpressed when he was dragged to Egypt with the rest of them.
Why is YHWH opposed to Jewish settlement in Egypt?
Aside from the reasons outlined above, we must bear in mind that the whole point of the Exile was to teach Judah/Israel to trust in YHWH alone - just as their ancestors learned during the Exodus. In one sense it's a replay of Numbers 14:4 where the people were on the brink of returning to Egypt rather than trust YHWH to enter the land, and YHWH threatened to destroy the entire community with a plague.
The problem in the first place is that Judah has forsaken YHWH and dug their own 'cisterns' of water (Jer 2:13), alternative sources of hope and strength. So until the people abandon all their cisterns and seek the one and only fount of living water, the job will not be complete.
YHWH sets out his plan clearly in Jeremiah 27 - every Kingdom has been given over to Babylon, and the 'safe path' for all is to listen to the word of YHWH and bow to the yoke of Babylon. Every man, woman and King has been given this command of YHWH, and from there the choice is to obey and drink this cup of wrath, or disobey and be crushed by it.
"Do not listen to them. Surrender to the king of Babylon, and you will live. Why should this whole city be destroyed?"
Jeremiah 27:17 NLT
Conclusion: Rejecting YHWH's plan
In response to Jeremiah's message, the people confirm their reading of the situation:
Azariah son of Hoshaiah and Johanan son of Kareah and all the arrogant men said to Jeremiah, “You are lying! The Lord our God has not sent you to say, ‘You must not go to Egypt to settle there.’ But Baruch son of Neriah is inciting you against us to hand us over to the Babylonians, so they may kill us or carry us into exile to Babylon.”
Jeremiah 43:2-3 NIV
The people are not choosing an alternative path of Exile, but rather opting out of the Exile itself, and rejecting YHWH's word which gave them clear instruction of how to obey him and where he intended to build and strengthen them.
They reject the Exile itself which YHWH repeatedly proclaimed and explained through Jeremiah, rejecting his promises to build them up and not tear them down in the land (Jer 32:10) and dispersing the people YHWH had already regathered to Jerusalem, returning to their familiar cisterns:
"So Johanan son of Kareah and all the army officers and all the people disobeyed the Lord’s command to stay in the land of Judah. Instead, Johanan son of Kareah and all the army officers led away all the remnant of Judah who had come back to live in the land of Judah from all the nations where they had been scattered."
Jeremiah 43:4-5 NIV
After they depart, the consequences begin to crystalize in Jeremiah 44, where YHWH continues to spell out the consequences of returning to Egypt and explain why it really wasn't a very good idea in the first place, for anybody interested in further reading.