From The Gospel of Matthew, by Curtis Mitch and Edward Sri, commenting on Matthew 1:18-24
Various views on the nature of Joseph’s quandary have emerged in the Catholic tradition.
According to one view, if Joseph found Mary pregnant and knew he was not the father, he might have suspected adultery. If so, he would be expected to bring Mary to public trial and accuse her. However, Joseph was unwilling to expose her to shame, meaning he did not want to publicly display the disgrace of her suspected adultery. Instead, he decided to divorce her quietly. If one did not go through a public trial, a bill of divorce could be drawn up privately and presented before two witnesses. As a righteous man, Joseph seeks divorce but his righteousness is expressed also in his mercy, since he seeks the divorce not through a public trial but through more private means.
Another possibility is that, from Joseph’s human perspective, it appears that Mary had been with another man, and even if this had been nonconsensual on her part, by Jewish law she would no longer be suited for marriage. Joseph thus finds himself in a situation in which he would be expected to divorce Mary, but he decides to do so “quietly” and not put her through a humiliating trial.
Another interpretation, known as the “reverential fear” view, was held by Sts. Thomas Aquinas, Bernard, Basil, and Ephraim. In this view, Mary told Joseph about her conceiving by the Holy Spirit and he responds with religious awe over the mystery of what God is working in Mary. Joseph decides to release Mary from the marriage obligation not out of anger or shame but out of a humble, holy fear that he is unworthy to be the husband of Mary or the father of this child.