Matthew 2:22

But when he heard that Archelaus did reign in Judaea in the room of his father Herod, he was afraid to go thither: notwithstanding, being warned of God in a dream, he turned aside into the parts of Galilee:

This verse belongs to the flight into Egypt, in which Herod waited anxiously for the wise men to return because he was impatient to carry out his determined purpose to destroy the infant King of Israel. When they delayed he feared his purpose would be thwarted and read their absence as insult and mockery, while his impatience, envy and hatred increased until, stirred by the devil, he determined to accomplish his purpose by a most cruel act of power and authority. That act was meant to strike terror into the hearts of all the Jews and to show them what would happen if they sought to place a king upon the throne in Jerusalem.

After Herod died Joseph returned to the land of Israel because an angel told him to return. He wanted to settle in Judah, in Bethany. Those who hold the other detail teach he desired to settle in Judah, in Bethlehem.

When he heard that Archelaus was reigning in Judea in place of his father Herod, he was afraid to go there, fearing the son would continue his father's murderous purpose to kill Jesus. The same fear is taught of returning to Judah, lest Herod's son who had taken his father's place should carry out the same plan. Archelaus is described as reigning on his tyrannical father's throne, and his succession had already brought violence in Jerusalem, including the slaughter of thousands of Jews by Roman guards, giving Joseph reason to avoid the region.

While Joseph was uncertain and perplexed and did not know where to live, God warned him in a dream and directed him through an angel to a place of safety. Through His angel God chose the place and turned him aside into Galilee. In obedience Joseph took Jesus and Mary and settled in Nazareth, his old home. This dwelling in Nazareth fulfilled what the prophets had spoken, that Jesus would be called a Nazarene.

This shows the reception Christ met in coming to a fallen world, with no rest or safety for the infant Saviour among the very ones He came to benefit. God would not trust His Son to men but sent angels to attend Him and preserve His life until His earthly mission was accomplished and He died by the hands of the men He came to save.