Romans says the law brings the knowledge of sin rather than justifying people by works. The law speaks truthfully, exposes guilt, and closes the mouth of human boasting, but it does not provide a way for sinners to declare themselves righteous.
Romans 3:19-20 comes just before Paul's announcement that God's righteousness has now been revealed apart from the law. The law's exposing work prepares readers to understand justification by grace.
This helps readers stay clear of turning God's law into a ladder for self-salvation. Romans honors the law's truth while showing why salvation must come through Christ.
Paul is not calling the law evil. Later he will say the law is holy. The issue is what the law can and cannot do for sinners.
Original wording based on Romans 3 and Romans 7's later clarification.