Paul understood the purpose of the law. He knew that it was directed towards those who would disrupt the peace of society.
We know that the law is good if one uses it properly. We also know that law is made not for the righteous but for lawbreakers and rebels, the ungodly and sinful, the unholy and irreligious; for those who kill their fathers or mothers, for murderers, for adulterers and perverts, for slave traders and liars and perjurers (1 Tim 1:7-9).
Paul says the law is not for the righteous. The law is for thieves, murderers, adulterer and perjurers. These are the people who disrupt peaceful and harmony of society. The righteousness of Jesus cannot deal with these people, as they are hostile to him. Until they are transformed by the love of Jesus, society will need the laws that prevent them from harming other people. Law provides a solution to the problem caused by people who are willing to harm others. It is the only way to deal with them.