When they had departed, behold, the angel of the Lord appeared to Joseph in a dream and said, "Rise, take the child and his mother, flee to Egypt, and stay there until I tell you. Herod is going to search for the child to destroy him." Joseph rose and took the child and his mother by night and departed for Egypt. He stayed there until the death of Herod, that what the Lord had said through the prophet might be fulfilled, "Out of Egypt I called my son." When Herod realized that he had been deceived by the magi, he became furious. He ordered the massacre of all the boys in Bethlehem and its vicinity two years old and under, in accordance with the time he had ascertained from the magi. Then was fulfilled what had been said through Jeremiah the prophet: "A voice was heard in Ramah, sobbing and loud lamentation; Rachel weeping for her children, and she would not be consoled, since they were no more." (Mt 2:13-18)
Herod the king has been deceived by the magi. Herod had evil plans in his mind. He wanted to destroy the child so that he would not have any opposition to his position. He was ruled by his desire for position. For, Herod eliminated anyone who stood against his position. He thought that he was in control of the situations but in fact he was not.
God was in control of the situation. He wanted to save Jesus and let this be known in a dream to Joseph. The author also makes uses of this to reveal that Jesus came from Egypt. Matthew the author tries to show Jesus as the new Moses and Jesus as the new Israel. So he brings him out of Egypt. "Out of Egypt I called my son." (Hosea 11:1)
Herod was furious and his wrath had it way. He killed the male children who were in Bethlehem. Why did these children die? At times evil has it time. We have an example in the case of Job. There could be other examples from the scriptures. The extend of the fury of Herod is narrated. Jesus himself faced the similar situation at the end of his life. Why should this happen? The author finds a biblical passage to prove this. It is the fulfillment of the scriptures. The authors’ faith.