According to the Catholic Church, this is a most interesting situation and poses many possible interpretations and possibilities.
Scripture tells us that "before they came together she was found to be with child of the Holy Spirit." Thus the Marriage of the Blessed Virgin Mary was not consummated. Thus is a further reason why Joseph would desire to divorce Mary with no fanfare. St. Joseph did not consider issuing her a Bill of Divorce because he was "a just man."
St. Joseph desired to divorce Mary privately and without any fanfare in order not to damage Mary’s reputation!
But why did St. Joseph desire to put Mary away quietly? Pope Benedict XVI speaks of an alternative interpretation that may be plausible and compatible to Catholic theology.
Joseph was afraid to take Mary as his wife because he knew she was conceived by the Holy Spirit. This situation is plausible but not wholly accepted yet by the Church.
Matthew tells us that when "Mary had been betrothed to Joseph, before they came together she was found to be with child of the Holy Spirit; and her husband Joseph, being a just man and unwilling to put her to shame, resolved to divorce her quietly."
The view that suggests itself to most people is that Joseph thought Mary had been unfaithful to him.
But there is another theory: that Joseph knew the Child had been conceived "of the Holy Spirit" and so Joseph was afraid to take Mary as his wife.
What are we to make of this issue?
And what does Pope Benedict have to say in his new book, Jesus of Nazareth: The Infancy Narratives
The idea that Joseph did not think Mary had been unfaithful to him may be suggested by the fact that Matthew mentions the miraculous conception of Jesus before he introduces Joseph's idea of divorce.
He says: "before they came together she was found to be with child of the Holy Spirit."
Found by whom? Who knew that the Holy Spirit was responsible for the pregnancy?
Presumably, Joseph would have been one of the first to be told.
If he believed this then one could understand why he would be afraid to take Mary as his wife.
Who wouldn't hesitate to take to wife someone who, in later centuries, would be called "the spouse of the Holy Spirit"?
Thus, as a "just man" he might seek to quietly sever the legal bond between them and would need the assurance of the angel telling him "do not fear to take Mary your wife."
On the Other Hand . . .
The angel didn't stop by saying Joseph shouldn't fear to take Mary as his wife. The angel continued "...for that which is conceived in her is of the Holy Spirit."
If Joseph already believed that the Holy Spirit was responsible for Mary's condition, why would the angel say this?
The fact the angel says it suggests that Joseph did not yet believe this about Mary's pregnancy. If he already believed it, why tell him as an explanation of why it's okay to take Mary home as his wife?
It suggests that either he had not heard that the Holy Spirit was responsible or he had heard it but not yet come to accept it.
An Intermediate Position?
According another view, which is in some ways between the two just mentioned, Joseph simply did not know what to think.
On the one hand, he did not think that Mary had been unfaithful, but he also did not know how to explain her pregnancy. He thus left open the question of how she became pregnant . . . chastely.
While Joseph might have had such a view pass through his mind, it is difficult to see this as a settled position.
In any event, the "Joseph did not know what to think" view, like the "Joseph thought Mary was unfaithful" view, presupposes that he did not (yet) believe that the Child was of the Holy Spirit.
The fundamental question is still: Did he believe this yet or not?
This is a case where the Church Fathers do not have a united opinion.
What does Pope Benedict say?
In his new book, Jesus of Nazareth: The Infancy Narratives, Pope Benedict takes the position that Joseph did not yet believe that Mary had conceived by the Holy Spirit. He writes:
Joseph had to come to terms with the fact that Mary “was with child of the Holy Spirit” (Mt 1:18).
With regard to the child’s origin, Matthew is anticipating something here that Joseph does not yet know. Joseph has to assume that Mary has broken their engagement, and according to the law he must dismiss her. He has a choice between a public juridical act and a private form. He can bring Mary before the court or he can issue her with a private writ of divorce. Joseph decides on the latter option, in order not “to put her to shame” (1:19). Matthew sees in this choice an indication that Joseph was “a just man.” . . .
After the discovery that Joseph made, his task was to interpret and apply the law correctly. He does so with love: he does not want to give Mary up to public shame. He wishes her well, even in the hour of his great disappointment. He does not embody the form of externalized legalism that Jesus denounces in Mt 23 and that Paul opposes so strenuously. He lives the law as Gospel. He seeks the path that brings law and love into a unity. And so he is inwardly prepared for the new, unexpected and humanly speaking incredible news that comes to him from God. . . .
The message conveyed to Joseph is overwhelming, and it demands extraordinarily courageous faith. Can it be that God has really spoken, that what Joseph was told in the dream was the truth—a truth so far surpassing anything he could have foreseen? Can it be that God has acted in this way toward a human creature? Can it be that God has now launched a new history with men? Matthew has already said that Joseph “inwardly considered” (enthymẽthéntos) the right way to respond to Mary’s pregnancy. So we can well imagine his inner struggle now to make sense of this breathtaking dream-message: “Joseph, son of David, do not be afraid to take Mary your wife, for that which is conceived in her is of the Holy Spirit” (Mt 1:20).
Is This View Mandated?
Pope Benedict famously wrote in the first volume of his Jesus of Nazareth series:
It goes without saying that this book is in no way an exercise of the magisterium, but is solely an expression of my personal search “for the face of the Lord” (cf. Ps 27:8). Everyone is free, then, to contradict me. I would only ask my readers for that initial goodwill without which there can be no understanding.
One thus can maintain either theory.
At the same time, if one thinks that Joseph already believed that Mary had conceived by the Holy Spirit, one should acknowledge that the other view can also be held by a pious Catholic. - Why Did Joseph Plan to Divorce Mary?