Notice that it is God Himself who guides the Holy Family under the protection of St. Joseph. Yes, there are times where the Holy Family encounters hardships of the everyday life, but the eternal God never ceases to guide them. God does not abandon them.
Since St. Joseph is the head of the Holy Family, God gives him, not Mary, the revelation that they needed to flee to Egypt and remain there until He tells him in particular, not Mary (Matt 2:13). Again, it is because Joseph is the Head of his family. His position is a matter of the role that has given to him. His call did not depend on his knowledge or holiness because if it were so, then God would have given this message through His Angel to Mary (the Immaculate Conception [this will be explained on a separate thread]) who is holier than Joseph.
Then we see that Joseph got up that same night and took Jesus and Mary in order to go to Egypt (2:14). We don’t see any complaint or disobedience from Mary. Joseph’s wife obeyed him. Mary obeyed her husband.
Then, after Herod has died, God’s Messenger (the Angel) went back to Joseph in order to communicate him that it was the time to go to Israel (2:19-21). Again, the message was given to Joseph, not Mary, not even Jesus who is God Himself and, humanly speaking (regarding His human nature), at this point He might have reached the age or reason.
Then, by Joseph’s prudent decision, he took his family to Nazareth (2:22-23). This was his personal decision.
So we see here, that God chooses one head (not two, or three or more heads for the same family or body). In the case of the Holy Family, God chose St. Joseph the role to be in His place in order to fulfil Jesus’ fatherly obligations on earth, as well to be Mary's husband, and guide the Holy Family. We see that God gives 'order' in the different roles to each person within the members of a family accordingly.
John 3:27; John 15:5; Matthew 19:26