“Now we know that whatever things the law says, it says to them who are under the law: that every mouth may be stopped, and all the world may become guilty before God.
Therefore by the deeds of the Law shall no flesh be justified in his sight: for by the Law is the knowledge of sin.”
The Law was not given to everyone; it was given only to the children of Jacob; it applied exclusively to them. But there’s the rub: the list of judgements, ordinances, and rituals given to Israel by God through Moses could not make them ‘good’. All it could do is show them how desperately far they were from attaining perfection, and how completely impossible it would be for them to ever succeed at attaining it. Rather than being their vehicle of redemption, it was a witness against them to their condemnation; it declared them to be just like their neighbours: unrighteous and guilty before God.
When God led the children of Israel out of Egypt, He gave them an invitation. “if they would obey His voice and keep His covenant, they would be a special treasure to Him above all nations of the world, a holy nation with a direct and intimate relationship with YHWH the living and true God. When they expressed their acceptance of His offer, He then invited them to meet with Him at Mount Sinai, where He would speak to them.
But when YHWH spoke to them the words of His covenant, which we know as the Ten Commandments, they were afraid to hear His voice. In their unfaithfulness, they removed themselves from near the mountain, and declared their separation from the God Who had invited them into fellowship with Him. The told Moses that he could speak to them, and they would listen, but that God was not to speak to them directly ‘lest they die’. They did not consider that God had invited them to Himself and He would certainly not destroy them for entering into His presence, but instead responded with fear and unbelief, preferring to remain at a distance rather than enjoy true fellowship with the Lord God Almighty. The list of rules that made up the Law, rather than making them righteous, was God’s response to their unfaithful rejection of His invitation to fellowship in His presence. Rather than their salvation, it was their condemnation.