 The Jewish law is like this, a womans first baby boy belongs to God. And after a baby boy is born, the mother cant go into Gods ceremony house or do any of their ceremonies for the next 40 days. It is like she is not clean. Then, after 40 days, she has to go to Gods ceremony house in Jerusalem. She has to get a leader of the Jewish ceremonies there to kill 2 pigeons and burn them, and let the smoke go up to God. This will make her clean again for Jewish ceremonies. So Joseph and Mary went to Jerusalem at the right time to follow that law. They took baby Jesus with them. 