This fulfilled the word spoken through Jeremiah the prophet:
A voice was heard in Ramah, weeping and much grieving. Rachel weeping for her children, and she did not want to be comforted, because they were no more.
References for Matthew 2:18
After King Herod died, an angel from the Lord appeared in a dream to Joseph in Egypt.
References for Matthew 2:19
"Get up," the angel said, "and take the child and his mother and go to the land of Israel. Those who were trying to kill the child are dead."
Joseph got up, took the child and his mother, and went to the land of Israel.
But when he heard that Archelaus ruled over Judea in place of his father Herod, Joseph was afraid to go there. Having been warned in a dream, he went to the area of Galilee.
He settled in a city called Nazareth so that what was spoken through the prophets might be fulfilled: He will be called a Nazarene.