When the time of their purification according to the Law of Moses had been completed, Joseph and Mary took Him to Jerusalem to present Him to the Lord (as it is written in the Law of the Lord, “Every firstborn male is to be consecrated to the Lord”). Luke 2:22-23
Joseph and Mary consecrated the baby Jesus to the Lord in order to keep a law that had been given by Moses thousands of years earlier. God knew long before Moses that Christ would be the firstborn son of a virgin mother, so He declared that all firstborn male children belonged to Him. However, instead of requiring lifelong service from each of these firstborn sons, He accepted the service of Levite men in place of the firstborn of Israel.