Joseph to the Rescue
From the devotional Day by Day in the Gospel of Matthew by Chuck Gianotti.
Now when they had gone, behold, an angel of the Lord appeared to Joseph in a dream and said, “Get up! Take the Child and His mother and flee to Egypt, and remain there until I tell you; for Herod is going to search for the Child to destroy Him.” So Joseph got up and took the Child and His mother while it was still night, and left for Egypt. He remained there until the death of Herod. This was to fulfill what had been spoken by the Lord through the prophet: “Out of Egypt I called My Son.”
The visit of the magi must have bewildered Joseph, the newly adoptive father of Jesus. We know little of his background other than that he was a skilled tradesman (3:55). The enormity of the events likely left him with a lack of perspective, an inherent insecurity, and indecision about the next course of action. Fortunately, God provided angelic guidance, warning him to get out of town, as it were, because Herod had set his sights on murdering the Child. Note how early Jesus encounters conflict!
Not only did Joseph and Mary have to deal with the nasty rumors of having an illegitimate child, but now the child’s life was in danger. The only remedy? Flee the country. It’s not hard to imagine the difficulties of establishing a marriage and family under such conditions, apart from the support of extended family and friends. This poor young couple, blessed and unfortunate at the same time, had been dealt a difficult hand in life.
Interestingly, God speaks directly to Joseph (the non-birth parent) rather than Mary (the biological/birth parent) about what to do next, which justifies our assumption that Joseph was considered the adoptive parent with all its responsibilities, legal and otherwise. He was not just a parent, but a father. Indeed, God gives the father greater responsibility in guiding and protecting the family (see Genesis 2, Ephesians 5:22ff).
Few things stir masculinity in a man like a threat to his children. So Joseph immediately (“while it was still night”) responds to the divine warning to protect his family and flees with them to Egypt.
Matthew, inspired by the Holy Spirit, adds that this action, in addition to the safety factor, sets the stage for the fulfillment of prophecy (Hos. 11:1). Thus Matthew continues his book-long effort to show Jesus as the fulfillment of OT prophecies for Israel.