Galatians 3:19
“Why then the law? It was added because of transgressions, until the offspring should come to whom the promise had been made;”

the law was given because of transgressions to highlight the presence of sin and demonstrate the need for a Savior. It served as a temporary measure until the coming of Jesus Christ, who fulfilled the promise made to Abraham and provided salvation by grace through faith.