And why does the Bible call him a just man for taking such an action. I'm sure it's because he saw people instead of law. Jesus said later, "I desire mercy not sacrifice." He saw the law of Moses in a godly and just way. It says further that he did not want to put her to public disgrace. Everyone would eventually understand she had been unfaithful to him. Her being unfaithful to him warranted some kind of action.
However his action was a just action. What was the justice in his action? It was not bringing her out into the public as an adulterer. His hope was to keep the situation quiet so that she would not ultimately die under the judgment of the community by Stoning. Here's what the Bible says about how Joseph handled the situation...
“And her husband Joseph, being a just man and unwilling to put her to shame, resolved to divorce her quietly. But 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. She will bear a son, and you shall call his name Jesus, for he will save his people from their sins.”
So then Joseph had a dream. He dreamt and had a vision. The Lord told him what to do in this situation. But before he dreamed, Matthew said he was "considering these things." A righteous and just man must consider and pray, and consider and pray, and be open to what the Lord is saying to him. And often as the Lord does when you consider and pray, and consider and pray, he appears to you. He speaks to you. He shows you what you're supposed to do. And God appeared through the angel in his dream and showed him what to do. The first thing the Angel of the Lord says is not to be afraid to take Mary as his wife. Now why would he be afraid to take Mary as his wife? The shame, being culturally ostracized, and of course having a son in your life that is forever called the "son of Mary." Which was saying in effect this boy of yours, who you've claimed as your son, is a bastard. The angel said to him, "do not be afraid" of this life that you will take up. Do not be afraid to call this child your own. Do not be afraid of what man will say to you. Fear God alone. God was saying, "this is my plan you can do this." But then the rubber met the road, and Joseph woke up from the dream what would he do?
When Joseph woke from sleep, he did as the angel of the Lord commanded him: he took his wife, but knew her not until she had given birth to a son. And he called his name Jesus.”
Matthew 1:19-21, 24-25
It says when he woke up he did is the angel of the Lord commanded him. Righteous men do what God commands them to do. Righteous men obey, not because they're seeking the approval of God, but because they already have His approval. Jesus needed a righteous earthly father so that he could learn what it means to, as the Scripture says, "he learned obedience." Does that mean Jesus didn't obey at some point? No, he had to see example, he had to learn it through another living human, another man who also obeyed God consistently. Joseph was that man. Another opportunity we see Joseph is taking his family to Jerusalem to worship at the Passover. This was also an act of obedience to worship God through the Passover.
We don't know much more about Joseph. The Scriptures is kind of silent after this point besides a few other mentions of him. Joseph consistently led his family in the way God asked him to lead his family. He obeyed God, and he was a just man who consistently did that. The Scriptures are relatively silent other than these few passages on Joseph the man and father. This is all we have about him and it is enough. If anyone ever wrote about me anywhere, and would describe me as a just and obedient man, father, friend, husband, colleague, son, and brother then that would be enough. It is enough for God to decide to make Joseph Jesus earthly father, and its more than enough for us as fathers and leaders of our families. So this Christmas ask God to make you a JUST and OBEDIENT Man! He will do it just He did for Joseph. Below is a song about Joseph written and performed by Michael Card. Merry Christmas!