Moses
Egypt
Egypt was a safer place for Mary and Joseph than Bethlehem because Egypt was out of the jurisdiction of King Herod, who was seeking to kill the infant Jesus. By fleeing to Egypt, Mary and Joseph were able to escape Herod's massacre in Bethlehem targeting male infants.
When word got out that King Herod was after Jesus and his family, they escaped to Egypt. Jesus was thought to be the King of Kings and Herod thought of him as a threat.
God warned Joseph in a dream to take Mary and Jesus to Egypt to avoid the wrath of Herod.
So they could escape from Herod and his soldiers
In Matthew 2:13-23, Joseph is told in a dream to go to Egypt because King Herod wanted to kill him. If you recall the story of the Magi, they were originally sent by Herod as well, but they avoided him instead of telling him where Jesus was. Herod was jealous that there would be another king rising up among the people, which is why he wanted Jesus dead. So Joseph moved to Egypt to protect his family.
The angel said this to Joseph in a dream. So they all three fled to Egypt.
Jesus escaped to Egypt from Bethlehem, not Nazareth. King Herod, who wanted to kill him, ordered the massacre of all infant boys in Bethlehem, prompting Joseph and Mary to flee to Egypt with Jesus to keep him safe.
Jesus' parents, Mary and Joseph, hid him in Egypt on the continent of Africa to escape King Herod's order to kill all baby boys in Bethlehem.
AnswerIn Matthew's version of the nativity of Jesus, Joseph and Mary fled with Jesus from Bethlehem to Egypt to escape King Herod, who wanted to have Jesus killed. After Herod died and it appeared safe to do so, they began the journey back to their home in Bethlehem, but being warned in a dream turned aside and made the long journey to Nazareth in Galilee instead.
Jesus, Mary, and Joseph fled to Egypt to escape King Herod's order to kill all male infants in Bethlehem. They remained in Egypt until it was safe to return to Israel, settling in Nazareth. This event is known as the Flight into Egypt and is recorded in the Gospel of Matthew.
Possibly in his 40's-50's, the Bible does not say, but Jewish extra-biblical sources say he was an older man (not aged) and Jesus had brothers and sisters, so he can't have been too old to father children.