Caesar Augustus taxed everyone, so, Mary and Joseph had to make the trip to the city of David, aka Bethlehem-Judah.  Then what follows is very interesting.

And all went to be taxed, every one into his own city.

And Joseph also went up from Galilee, out of the city of Nazareth, into Judaea, unto the city of David, which is called Bethlehem; (because he was of the house and lineage of David:)

To be taxed with Mary his espoused wife, being great with child.