He went there to register with Mary, who was pledged to be married to him and was expecting a child. Luke 2:5.
There is no mention of a donkey for the journey that Joseph and Mary took to Bethlehem for Caesar's census, or that the number of wise men were three when they came to worship the newly born king, so there is a bit of artistic license in biblical art at times. A donkey would not be out of place though.Luke 19:30-38.
The babe in the manger would grow up in the Spirit of the Lord and yearly would travel to Jerusalem for the passover.Luke 2:41-52.