The Lord told Israel,
“Consecrate to Me all the firstborn, whatever opens the womb among the children of Israel, both of man and beast; it is Mine” (Exodus 13.2).
Why did the Lord have this law concerning the first born?
We do know from elsewhere that God required the first born, because He took the firstborn of the Egyptians. However, this also prefigured the Messiah being the first born to a human family, which would further substantiate the virgin birth.
As Matthew wrote that Joseph,
“…did not know [Mary] till she had brought forth her firstborn Son. And he called His name Jesus” (Matthew 1.25).
Luke showed the fulfillment of Exodus 13.2 in the baby Jesus,
“Now when the days of her purification according to the law of Moses were completed, they brought Him to Jerusalem to present Him to the Lord (as it is written in the law of the Lord, ‘Every male who opens the womb shall be called holy to the Lord’)” (Luke 2.22, 23).