Righteous.
This is the word used in the same sentence about a man choosing divorce in light of (assumed) adultery. The Bible has forever associated the word righteous with the choice to divorce. It is part of the Christmas story!
God does not shame Joseph in this passage for deciding to divorce a pregnant Mary. It is assumed that is what a righteous man would do when he found his betrothed–essentially spouse–pregnant by another.
Hadn’t he heard of Hosea and Gomer?!
Did the local rabbi never read Malachi 2 about God hating divorce to Joseph?
How could he choose to divorce?
You see that these poor applications were not accepted as wisdom in Joseph’s day. The choice was clear for those who sought to follow God back then: They were to divorce the unfaithful spouse!
We need to get back to this assumption, in my opinion.
When we do not hold this assumption, we shame the wrong party in this matter. The divorce is NOT what is shameful here. Joseph was doing NOTHING shameful by choosing to divorce Mary (until God intervened, of course).
What is shameful is adultery!
God was not confused about that back in Joseph’s day. And He is not confused about that today. It is only some of His people that have lost their way on that subject.