4 So Joseph also went up from the town of Nazareth in Galilee to Judea, to Bethlehem the town of David, because he belonged to the house and line of David. 5 He went there to register with Mary, who was pledged to be married to him and was expecting a child. (Luke 2:4-5)
Joseph traveled to Bethlehem because of family. Mary went with him because of family. They traveled together because they had committed to each other to be a family. Often times it comes down to family.