Joseph probably suspected adultery on the part of Mary and was planning to divorce her. He could have accused Mary publically, subjecting her to a shameful trial (cf. Num 5: 11-13). But this he was unwilling to do, and he decided to divorce her privately. That is, without exposing Mary to public disgrace. This decision of Joseph is related to his being a “just man” (Mt 1: 19). Here the expression ‘just man’ may simply mean ‘upright man,’ ‘law-abiding,’ or ‘observant of the law,’ or ‘obedient to the law.’ four times in the infancy narrative of Matthew Joseph is portrayed as being totally obedient to the divine directives (cf. Mt 1: 24; 2: 13-14, 20-21, 22). The meaning of verse 19 would then be as follows: being obedient to the law Joseph wants to fulfil what the law requires and yet he chooses a course of action that will not put Mary to shame but will show kindness to her.
Some scholars also interpret this verse differently. Understanding the word ‘just’ as ‘God-fearing,’ ‘pious,’ or ‘devout’ they suggest that Joseph knew about the divine intervention in the conception of the child and that out of fear and awe in the presence of the divine he did not want to expose Mary to public disgrace or even to accept her as his wife. Therefore the messenger of God had to command him to take Mary as his wife (Mt 1: 20). Attractive though this interpretation is, it leaves several questions unanswered. How did Joseph know that the child had been divinely conceived? If he had known this already why was he also contemplating on divorcing Mary (quietly) in accordance with the prescriptions of the law? Therefore the interpretation that does justice to the Matthean text seems to be first one which shows that in spite of being obedient to the law, Joseph is also kind and considerate towards Mary.
As Joseph was planning to divorce Mary, a divine messenger appeared to him in a dream. Probably the angel of the Lord is the Lord himself in a visible form (cf. Gen 16: 7, 13; 22: 11, 14; Judg 6: 12, 14, etc). The angelic message to Joseph concerns the supernatural origin of the child and the role which is assigned to Joseph.