Joseph was afraid to take Mary as his wife (see Joseph's Dilemma). Perhaps he was afraid because of lawful reasons. Perhaps he was afraid because he did not want to bring dishonor to his family's name. However, when Joseph was still in the process of considering his many options, he had a dream:
But when he had considered this, behold, an angel of the Lord appeared to him in a dream, saying, "Joseph, son of David, do not be afraid to take Mary as your wife; for the Child who has been conceived in her is of the Holy Spirit. (Matthew 1:20)Joseph must have been shocked that the angel of the Lord spoke to him through a dream. Surely, as a Jew, he realized that throughout history God had often revealed marvelous wonders through dreams! Joseph (the other one) witnessed prophetic events in his dreams which foretold the day that his brothers would bow down to him in Egypt. While in Egypt, Joseph also interpreted the dreams of a cupbearer, a baker, and Pharaoh himself. Daniel likewise interpreted the dream of the great king Nebuchadnezzar. Joel also prophesied of a coming day in which God would pour forth His Spirit on mankind, sons and daughters would prophesy, and old men would dream dreams (Joel 2:28).
However, the event that the angel of the Lord mentioned, that the child conceived in Mary was of the Holy Spirit, had never occurred. No person had ever been born of a virgin. Adam was made from the dust; Eve was made from one of Adam's ribs, but no man had ever been found to be with child by the Holy Spirit (Matthew 1:18).
To marry Mary or not to marry Mary? The question must have had a constant presence in Joseph's mind. How he responded to this question would have a great impact on the remainder of his life. Fortunately, Joseph did not have to decide for himself. The angel of Lord told Joseph exactly what he should do: do not be afraid to take Mary as your wife.
There's a certain amount of irony in this statement, "do not be afraid". Don't be afraid Joseph! Mary is pure; take her as your wife. Don't be afraid Joseph! Mary is only pregnant by the Holy Spirit... something that has never occurred in all of human history. Don't be afraid Joseph! This is just the beginning of the fulfillment of many prophecies. Don't be afraid Joseph! This is just the unfolding of the events which the past prophets longed for... Don't be afraid Joseph!
Joseph heeded the angel's advice, for Matthew records that he did as the angel of the Lord commanded him, and took Mary as his wife (Matthew 1:24). In the middle of such strange and mysterious events, Joseph was obedient to God. He chose to trust God and do as the angel of the Lord suggested, regardless of the consequences that it might bring.
Jesus' Purpose: To Save His People From Their Sins (Part 1) - Matthew 1:21
Joseph's Dilemma - Matthew 1:19
The Virgin Birth - Matthew 1:18
The Creation of Man - The Christian Worldview
The Lineage of the Messiah - Matthew 1:1-17