Why was Joseph chosen to be betrothed to Mary?

We don’t have much background about Joseph, and he never speaks in the Gospels. That said, the things we do know point to a man who had integrity and compassion. Matthew ‘s gospel describes him as a “righteous” (1:19) man who was deeply concerned when he learned Mary was pregnant, which indicates that he cared about following the Mosaic law; at the same time, Matthew explains that Joseph was “unwilling to expose her to shame,” and chose to divorce Mary quietly rather than expose her to a possible death by stoning. This reaction indicates that Joseph was not a vindictive man, but one who could have deep compassion even for someone whom he assumed had wronged him. Later, Joseph’s actions in taking Mary and Jesus to safety in Egypt point to a man who was a strong protector of his family. These personal qualities no doubt made him a very good partner for Mary, both in the eyes of her family and in the eyes of God (naturally, they also made him a very good father-figure for the young Jesus).
On another level, Joseph was also from the House of David, which is consistent with Old Testament references to the Messiah coming from the line of David. (Even though Joseph was not technically the father, accepting Jesus as his son would have made Jesus a member of the House of David.)