This was something not expressly commanded by the angel. Could it be that he made this decision in order to avoid endangering either Mary or the child? We today know that relations are normally not harmful until maybe the last month of the pregnancy, but perhaps that was not known at the time. Is this why Joseph judged it best to abstain?
It’s unlikely. The reason for Joseph’s abstinence most likely has to do with him being a righteous man, one who greatly respects God's miraculous work in the womb of Mary. Joseph would have known the miraculous conception of this child, by the Holy Spirit. Joseph respects that her womb is an object of the Lord’s mysterious work. And so he desires that the supernatural conception of this child be made perfectly clear.
For it does not take much to imagine how the Jews in Joseph’s day could have looked with suspicion at this pregnancy, or later at Jesus himself. “Oh, Jesus is probably just Joseph’s natural son, conceived out of wedlock perhaps, but still Joseph’s natural son.” It has to be absolutely clear that this child is not born in any way by the power or the will of man, but of the Spirit. That’s why Matthew makes sure to say that Joseph “knew her not until she gave birth to a son.”
25 but knew her not until she had given birth to a son. And he called his name Jesus.