Matthew's gospel account
When the Magi come in search of Jesus, they go to Herod the Great in Jerusalem and ask where to find the newborn "King of the Jews". Herod becomes paranoid that the child will threaten his throne, and seeks to kill him (2:1–8). Herod initiates the Massacre of the Innocents in hopes of killing the child (Matthew 2:16–Matthew 2:18). But an angel appears to Joseph in a dream and warns him to take Jesus and his mother into Egypt (Matthew 2:13).
Egypt was a logical place to find refuge, as it was outside the dominions of King Herod, but both Egypt and Israel were part of the Roman Empire, linked by a coastal road known as "the way of the sea", making travel between them easy and relatively safe.
Return from Egypt
After a time the holy family returns from Egypt. The text states that Herod had died. Herod is believed to have died in 4 BC, and while Matthew does not mention how, the Jewish historian Josephus vividly relates a gory death.
The land that the holy family return to is identified as Judah, the only place in the entire New Testament where Judah acts as a geographic description of the whole of Judah and Galilee Matthew 2:20, rather than as referring to a collection of religious people or the Jewish people in general. It is, however, to Judah that they are described as initially returning, although upon discovering that Archelaus had become the new king, they went instead to Galilee. Historically, Archelaus was such a violent and aggressive king that in the year 6 AD he was deposed by the Romans, in response to complaints from the population. Galilee was ruled by a much calmer king, Herod Antipas, and there is historical evidence that Galilee had become a refuge for those fleeing the iron rule of Archelaus.
Prophecy of Hosea
Matthew 2:15 cites 11:1 as prophetically fulfilled in the return of Joseph, Mary and Jesus from Egypt:
"... and out of Egypt I called My son".
Matthew's use of Hosea 11:1 has been explained in several ways. A sensus plenior approach states that the text in Hosea contains a meaning intended by God and acknowledged by Matthew, but unknown to Hosea. A typological reading interprets the fulfillment as found in the national history of Israel and the antitypical fulfillment as found in the personal history of Jesus. Matthew's use of typological interpretation may also be seen in his use of 9:1, and 31:15.
Another reading of Hosea's prophetic declaration is that it only recounts God summoning of the nation of Israel out of Egypt during the Exodus, referring to Israel as God's son in accordance with Exodus 4:22–23).
The Massoretic Text reads my son, whereas the Septuagint reads his sons or his children; the Massoretic Text is to be preferred, the singular being both consonant with the other words which are in the singular in Hosea 11:1 and with the reference to Exodus 4:22–23. The Septuagint reading may be explained as having been made to conform to the Hosea 11:2, they and them.
See also Hermeneutics and Jewish exegesis.