Passing through Jerusalem would have almost been an obligation for a Jew, and particularly so for Mary and Joseph, as the husband of Mary's cousin Elisabeth was a priest in the Temple. In fact, Uta Ranke-Heinemann (Putting Away Childish Things) wonders why Joseph did not leave Mary there with her cousin but took her at such a late stage of pregnancy to Bethlehem, where they knew no one and could not even find accommodation (Luke 2:7: "...because there was no room for them in the inn.").
Another Answer:
There are many differing views to this question concerning the travels of Mary & Joseph. But the only truth comes from the Scripture itself.
The Bible never describes the route, mode of transportation, living place, length of pregnancy, or the time of year. The Bible only says Mary came with Joseph. Could of walked, been on a donkey, camel or other means. As Joseph's lineage was from Bethlehem, hence the reason for their travels, most likely they stayed with a family member (Greek word 'kataluma' means guest room, lodging place or inn). It never says Mary gave birth that evening as is a popular belief but rather 'while they were there (in Bethlehem), the days were accomplised that she should deliver' (Luke 2:6). Arriving weeks before her due date would make a lot of sense and as God was the Father, I'm sure He planned the trip well.
Luke's Gospel says that Mary and Joseph had to travel from Nazareth in Galilee to Bethlehem in Judea, and be counted there for the census. However, scholars say that not only was the census at the wrong time for the nativity story in Luke's Gospel, there would never have been a requirement for Mary and Joseph to travel from Galilee where they would be taxed, to Judea where any census record would have no value in ensuring the collection of taxes. They say that the journey from Nazareth to Bethlehem simply did not happen.
At the time of Luke's journey from Nazareth to Bethlehem, Mary and Joseph were only bethrothed, and Mary was still a virgin. We can assume that they were both in their teens, with Mary probably in her early teens. Their parents would likely still have been alive and less than forty years old. If there really was a census during the reign of King Herod, something most scholars dipute strongly, then Joseph's parents would have been expected to go Bethlehem as well. Tradition tends to support the notion that Mary was also descended from King David, although the Bible is silent on this, in which case we could also expect her parents to travel to Bethlehem as well. However, for some reason, Luke's Gospel makes no mention of the extended family travelling together to Bethlehem.
Mary and Joseph had touse the straw on floor of the stable as a crib.
We do not know where Joseph was born. His ancestral home town was Bethlehem but he was probably not born there. Perhaps he was born in Nazareth where he was living at the time he tool Mary as his wife.
Herod the Great wanted to kill Jesus. When Joseph, Mary and Jesus fled to Egypt, Herod had no authority there. Even if he could have sent men into Egypt to kill Jesus, they probably could not have found the family.
Mary traveled to Bethlehem by riding on a donkey with Joseph.
Joseph and Mary traveled to Bethlehem , as it was told to go to their respective hometowns for the census.
He traveled from Nazareth to Bethlehem with Mary, where Jesus was born. From Bethlehem he took his family to Egypt. From Egypt they returned to Nazareth.
Joseph's ancestral home was Bethlehem. However, at the time he took Mary as his wife he was living in Nazareth.
Bethlehem
She traveled there with her husband Joseph, whose family was from Bethlehem.
It's not explicitly specified, so no one knows for certain.
a census
a person
yesbie
Mary and Joseph went to Bethlehem for the census because it was a requirement by the government for all residents to return to their ancestral hometowns to be counted.
Luke's Gospel says that Mary and Joseph had to travel from Nazareth in Galilee to Bethlehem in Judea, and be counted there for the census. However, scholars say that not only was the census at the wrong time for the nativity story in Luke's Gospel, there would never have been a requirement for Mary and Joseph to travel from Galilee where they would be taxed, to Judea where any census record would have no value in ensuring the collection of taxes. They say that the journey from Nazareth to Bethlehem simply did not happen.