Now the birth of Jesus Christ took place in this way. When his mother Mary had been betrothed to Joseph, before they came together she was found to be with child from the Holy Spirit. 19And her husband Joseph, being a just man and unwilling to put her to shame, resolved to divorce her quietly. 20But as he considered these things, behold, an angel of the Lord appeared to him in a dream, saying, “Joseph, son of David, do not fear to take Mary as your wife, for that which is conceived in her is from the Holy Spirit. 21She will bear a son, and you shall call his name Jesus, for he will save his people from their sins.” (Matthew 1:18-21)
--v. 18: "her husband Joseph". Betrothals in ancient Israel were different than engagements of our day. They were contracts and the betrothal was as good as the actual marriage-without the consummation. That's why in the next verse, Joseph is recorded as considering a divorce.
Compare Mt 1:20, “Mary, thy wife.” Betrothal was, in Jewish law, valid marriage. In giving Mary up, therefore, Joseph had to take legal steps to effect the separation. Jamieson, R., Fausset, A. R., & Brown, D. (1997). Commentary Critical and Explanatory on the Whole Bible--v. 19: Joseph, being a just man and unwilling to put her to shame, resolved to divorce her quietly. (ESV). The NIV says
Because Joseph her husband was faithful to the law, and yet did not want to expose her to public disgrace, he had in mind to divorce her quietly.
The Holy Spirit in His wisdom chose to include the word "just" here. Joseph is a just man. The Spirit didn't inspire Matthew to write Joseph was a good man, or Joseph was a kind man, or Joseph, being a man, but notes that Joseph was "just". What does this mean? Strong's word definition explains that here, just, or righteous means "relates to conformity to God's standard (justice; especially, just in the eyes of God; righteous)."
Joseph did not become angry, or run to his friends and complain about Mary, or immediately seek the rabbis. According to the Law in Deuteronomy 22:23-24, and Mary and Joseph were a couple living under the Law (Luke 2:22), this was supposed to happen:
"If there is a girl who is a virgin engaged to a man, and another man finds her in the city and lies with her, 24then you shall bring them both out to the gate of that city and you shall stone them to death; the girl, because she did not cry out in the city, and the man, because he has violated his neighbor’s wife. Thus you shall purge the evil from among you."
Yet Joseph did not want to make her a public example. Matthew Henry says,
But he was not willing to take the advantage of the law against her; if she be guilty, yet it is not known, nor shall it be known from him. How different was the spirit which Joseph displayed from that of Judah, who in a similar case hastily passed that severe sentence, Bring her forth and let her be burnt! Gen. 38:24. How good it is to think on things, as Joseph did here! Were there more of deliberation in our censures and judgments, there would be more of mercy and moderation in them. Henry, M. (1994). Matthew Henry’s commentary on the whole Bible.
--v. 20a: "But as he considered these things,"
Joseph was thoughtful mulling over his responsibility as a husband, as a God-fearer, as a citizen under the Law. Joseph was just in the eyes of God so he..."resolved to divorce her quietly." One can hardly imagine the spiritual and emotional distress of those moments. Here, Jamieson-Fausset-Brown have some words:
Who would not feel for him after receiving such intelligence, and before receiving any light from above? As he brooded over the matter alone, in the stillness of the night, his domestic prospects darkened and his happiness blasted for life, his mind slowly making itself up to the painful step, yet planning how to do it in the way least offensive—at the last extremity the Lord Himself interposes. (Jamieson, R., Fausset, A. R., & Brown, D., Commentary Critical and Explanatory on the Whole Bible.)--v. 20b: behold, an angel of the Lord appeared to him in a dream, saying, “Joseph, son of David, do not fear to take Mary as your wife, for that which is conceived in her is from the Holy Spirit.
Our Lord's timing is gracious indeed. One may have suspected Joseph of feelings of betrayal or anger. Or we may also alternately suspect Joseph of knowing Mary's character, believing her tale of conception by Spirit to bear the Messiah and thus perhaps Joseph was fearful of marrying a woman who was bearing the Messiah, and did not want to presume himself into such an exalted event. Is that why the angel said, "Joseph, do not fear to take Mary as your wife"? The word "fear" is the word phobos, meaning "I fear, dread, reverence, am afraid, terrified" according to Strong's. Was Joseph's reverence of the holy event part of his fear to continue with Mary? Or was his fear of taking on a harlot and assuming her guilt and reproach for her [perceived] immoral behavior? We do not know for sure, all we do know is the angel said that proceeding in marriage with Mary is something not to fear.
Our God salved Joseph's heart with a confirmation of the message that the Messiah is within his Mary, and Joseph knew a great, Divine work was progressing. Joseph obeyed God and continued with Mary. Matthew Henry says, "Note, It is a great mercy to be delivered from our fears, and to have our doubts resolved, so as to proceed in our affairs with satisfaction."
--v. 21: She will bear a son, and you shall call his name Jesus, for he will save his people from their sins.”
Matthew Henry again,
"He is here informed concerning that holy thing with which his espoused wife was now pregnant. That which is conceived in her is of a divine original. He is so far from being in danger of sharing in an impurity by marrying her, that he will thereby share in the highest dignity he is capable of. Two things he is told, (1.) That she had conceived by the power of the Holy Ghost; not by the power of nature. The Holy Spirit, who produced the world, now produced the Saviour of the world, and prepared him a body, as was promised him, when he said, Lo, I come, Heb. 10:5.
That she should bring forth the Saviour of the world (v. 21). She shall bring forth a Son; what he shall be is intimated,
[2.] In the name that should be given to her Son: Thou shalt call his name Jesus, a Saviour. Jesus is the same name with Joshua, the termination only being changed, for the sake of conforming it to the Greek. Joshua is called Jesus (Acts 7:45; Heb. 4:8), from the Seventy. There were two of that name under the Old Testament, who were both illustrious types of Christ, Joshua who was Israel’s captain at their first settlement in Canaan, and Joshua who was their high priest at their second settlement after the captivity, Zec. 6:11, 12. Christ is our Joshua; both the Captain of our salvation, and the High Priest of our profession, and, in both, our Saviour ... he is therefore able to save to the uttermost, neither is there salvation in any other.
A righteous, kind, just, patient, thoughtful, responsible man was Joseph, foster-father to Jesus. A righteous, kind, just, patient, thoughtful, responsible God is our Jesus, a name given to Joseph by heaven and the only name under which there is salvation
And there is salvation in no one else, for there is no other name under heaven given among men by which we must be saved. (Acts 4:12)