What does Matthew 1:20 mean?
From Joseph's initial perspective, his betrothed, Mary, has betrayed him. She has been found to be pregnant, and he is not the father. To assume she was unfaithful is exactly how anyone would react in that situation. If that is the case, Mary has violated the legally-binding agreement to marry Joseph. Yet Joseph shows an exceptionally decent response to what looks like obvious infidelity.Instead of flying into a rage or exposing her to the community, Joseph demonstrates that he is "a just man" (Matthew 1:19) by planning to divorce her a quietly as possible. He has no interest in bringing greater shame on her or her family.
Before he takes that action, however, an angel of the Lord shows up in one of Joseph's dreams. This is not the last time Joseph will have the experience of being directed by God through an angel messenger in a dream. This angel has a very specific message for Joseph: Don't divorce Mary!
More specifically, the angel calls Joseph a son of David, which backs up Matthew's message that Jesus, also, is a direct descendant of David. The angel tells Joseph not to be afraid to take Mary as his wife, despite his legitimate concerns about her pregnancy, and what it means about her character and trustworthiness. The angel reveals to Joseph what is really going on. She is not pregnant as a result of having sex with another man. The baby conceived in her is miraculously given from the Holy Spirit.