Some Christians assume that the law was given as a temporary way of righteousness until Christ came. The problem with this view is that at least three thousand years had gone when God gave the law. If a temporary system of righteousness was needed, why did God wait for so long to give it?
Nearly 400 years before the law was given, Abraham understood righteousness through faith in God (Rom 4:9). Moses was also accepted by faith, before God gave him the law (Heb 11:24, 25). If righteousness through faith was already available, why would God give a system of righteousness by law? Why would God replace a superior righteousness with an inferior law?
The answer is that God gave the law just when it was needed. Up until the time of Abraham, there was plenty of room in the world, so people did not need live in close proximity. When people had disputes, they could just move away from each other. By the time of Jacob, people were starting to live closer together and disputes over property were becoming prevalent (Jacob and Esau, Jacob and Laban). A system for resolving disputes was needed.
Then they went down to Egypt to live as slaves, with no choice but to accept the Egyptian system of justice. This changed when they escaped. With a million people living in a small country, disputes would be bound to occur. God have the law to deal with the problem. He gave it just when it was needed.
The law was a system of justice for dealing with disputes over property and to violence towards people. God gave the law to restrain crime. It never had any other purpose and that purpose has not changed. It was given when it was needed, because God’s timing is always perfect.