For as many as have sinned without law will also perish without law, and as many as have sinned in the law will be judged by the law.
This passage and others make one thing clear: there were people – the Jews – who were under the law that Moses received from God at Mount Sinai. On the other hand, there were people – the nations or the heathen – who were not under the law (cf. also 1 Corinthians 9:20.21).
The heathen who sinned were not under the law and will not be judged on the basis of the law. As sinners they will nevertheless “perish”. They will not be counted responsible for not keeping the law of Moses that they could not know. They are, however, responsible for rejecting the knowledge of God as Creator (cf. Romans 1:19-21). For the Jews who “have sinned” the details of the law of Sinai that they have transgressed will make the judgment more severe.
Both cases deal with people who have sinned and their judgment. In the early chapters of this epistle Paul is concerned with proving that all, both Jews and heathen, are lost on account of their sins and need the Saviour Jesus Christ.
Only later, in chapter 4, will Paul show that even before the death and resurrection of Jesus Christ, before the preaching of his gospel, people were justified in spite of their sins. Yet even there it is emphasized that justification was not based on works but on faith. It depended on their believing Him who justifies the ungodly (ch.4, vv. 4 & 5).