"And Joseph her husband, being a just man and not willing to make her a public example, was minded to put her away privily."
Here we find that Joseph was a man, who believed and followed the Law. He was also gentle and kind. This is a rebuttal to the atheists and other non-believers that say the Bible is brutal and unjust. According to the Law, Joseph could have had Mary stoned to death for unfaithfulness, but he didn't. The Law, like the laws in most countries, give the highest penalties for an infraction. Whoever, the judge, would have been, would have access the situation and penalized the transgressor. Joseph assessed the situation and was going to give her a minor penalty.
"But while he thought on these things, behold, the angel of the Lord appeared unto him in a dream, saying, “Joseph, thou son of David, fear not to take unto thee Mary thy wife, for that which is conceived in her is of the Holy Ghost. And she shall bring forth a Son, and thou shalt call His name Jesus, for He shall save His people from their sins.”"
WOW! Put yourself in Joseph's place. You have been a just man, righteous before the Law and now, you are visited by an Angel of the Lord. That had to be very overwhelming. Here, after reminding Joseph that he was part of the Messianic line, an angel of the Lord tells Joseph, three important things, his wife Mary is still a virgin, the baby is part human and part God and best of all, his name will be Y'shua, Yahweh Saves. God will save mankind, through the blood sacrifice of his son.
"Now all this was done, that it might be fulfilled which was spoken of the Lord by the prophet, saying, “Behold, a virgin shall be with child and shall bring forth a Son, and they shall call His name Emmanuel” (which being interpreted is, “God with us”)."
Now, the angel shows him how the scriptures, Isaiah 7:14, foretold of this situation. Therefore, Joseph gladly accepted Mary, as his wife, because he was a just and righteous man and wanted to follow the law.
"Then Joseph, being raised from sleep, did as the angel of the Lord had bidden him, and took unto him his wife, and knew her not until she had brought forth her firstborn Son. And he called His name Jesus."
Honestly, how could a just and righteous man not follow the Law and the Prophets, little alone an Angel of God.