It was God's will.
Matthew 2:13
And when they were departed, behold, the angel of the Lord appeareth to Joseph in a dream, saying, Arise, and take the young child and his mother, and flee into Egypt, and be thou there until I bring thee word: for Herod will seek the young child to destroy him.
2:14 When he arose, he took the young child and his mother by night, and departed into Egypt:
2:15 And was there until the death of Herod: that it might be fulfilled which was spoken of the Lord by the prophet, saying, Out of Egypt have I called my son.
The nation of Israel collectively and Jesus Christ are corresponding "types." Not of the Bible but of God's son, both of whom shares the same experiences in the world.
Ex 4:21 And the LORD said unto Moses, When thou goest to return into Egypt, see that thou do all those wonders before Pharaoh, which I have put in thine hand: but I will harden his heart, that he shall not let the people go.
22 And thou shalt say unto Pharaoh, Thus saith the LORD, Israel is my son, even my firstborn:
23 And I say unto thee, Let my son go, that he may serve me: and if thou refuse to let him go, behold, I will slay thy son, even thy firstborn.
circa 750 BC
Ho 6:1 Come, and let us return unto the LORD: for he hath torn, and he will heal us; he hath smitten, and he will bind us up.
2 After two days will he revive us: in the third day he will raise us up, and we shall live in his sight.
You are looking here a a death, burial, and resurrection, and you are given a time frame.
See context.
Ho 11:1 When Israel was a child, then I loved him, and called my son out of Egypt.
Mt 2:13 And when they were departed, behold, the angel of the Lord appeareth to Joseph in a dream, saying, Arise, and take the young child and his mother, and flee into Egypt, and be thou there until I bring thee word: for Herod will seek the young child to destroy him.
Matt 2:14 When he arose, he took the young child and his mother by night, and departed into Egypt:
15 And was there until the death of Herod: that it might be fulfilled which was spoken of the Lord by the prophet, saying, Out of Egypt have I called my son.
God is dealing with his son in the above passages. In Jeremiah that I quoted, he is dealing with a remnant, who proved to be disobedient and became cursed by God for going down to Egypt. He promises to kill them down there. He is not calling them out. This happened circa 580 BC.
Jer 42:7 And it came to pass after ten days, that the word of the LORD came unto Jeremiah.
8 Then called he Johanan the son of Kareah, and all the captains of the forces which were with him, and all the people from the least even to the greatest,
9 And said unto them, Thus saith the LORD, the God of Israel, unto whom ye sent me to present your supplication before him;
10 If ye will still abide in this land, then will I build you, and not pull you down, and I will plant you, and not pluck you up: for I repent me of the evil that I have done unto you.
11 Be not afraid of the king of Babylon, of whom ye are afraid; be not afraid of him, saith the LORD: for I am with you to save you, and to deliver you from his hand.
12 And I will shew mercies unto you, that he may have mercy upon you, and cause you to return to your own land.
13 But if ye say, We will not dwell in this land, neither obey the voice of the LORD your God,
14 Saying, No; but we will go into the land of Egypt, where we shall see no war, nor hear the sound of the trumpet, nor have hunger of bread; and there will we dwell:
15 And now therefore hear the word of the LORD, ye remnant of Judah; Thus saith the LORD of hosts, the God of Israel; If ye wholly set your faces to enter into Egypt, and go to sojourn there;
16 Then it shall come to pass, that the sword, which ye feared, shall overtake you there in the land of Egypt, and the famine, whereof ye were afraid, shall follow close after you there in Egypt; and there ye shall die.
There is much more to this interaction between these two and it doesn't get better. This is where the group who translated the Hebrew into Greek came from. God did not send them to Egypt to do that.