You point to Romans chapter 2:13. Here Paul rightfully says: “For not the hearers of the law are justified before God, but the doers of the law shall be justified.”
Paul is saying, that some people merely were ‘pretending’ to know the law – but how could they know the law, if they did not keep the law according to their deeds, as the law requires, but only by their words?
This is also seen in the verse before, Romans 2:12. “All who sin apart from the law will also perish apart from the law, and all who sin under the law will be judged by the law.” Here, Paul is essentially saying what James is also saying. “For whoever keeps the whole law and yet stumbles at just one point is guilty of breaking all of it.” (James 2:10).
Basically, both of these writers are saying that all of mankind has been placed in quite a predicament. If we don’t have the law, we will perish, yet if we do have the law, but violate the law in just one area of our lives (and all have fallen short of the glory of God; read Romans 3:23), then we are doomed as well.
Like I said: what a predicament! Yes, as Paul and James point out, if we FULLY DO according to the law (i.e. keep the law), then we shall be made righteous. Yet, as Paul points out in Romans 3:23, and James in James 2:10, this is impossible! So what are we to do?! We are doomed if we do, and we are doomed if we don’t. Has there ever existed such a man, that he was able to keep the law at all times throughout his entire life? That is, a man who was truly righteous?
In Romans 3:21 we find the answer to this question, and it gives the whole point, which the before verses had led up to: "But now the righteousness of God without the law is manifested, being witnessed by the law and the prophets; even the righteousness of God through faith in Jesus Christ for all those who believe.”
Here is the point! Men either toil and labor in their attempt to please God in their own strength (and not by faith), yet this is impossible, because we are all sinners by nature. Yet that curse has been broken through faith in the One who was – and is – without sin, the spotless Lamb of God, who takes away the sins of the world. He is indeed the Messiah of God, the Son of the living God.
So, as you see, in the first instance, Paul points to the truth about the law – that we’ll live if we keep it, and die if we don’t – and that since no one is able of keeping it, hence all are on the pathway to death (to perish, that is). No ordinary man can keep the law fully, thus being justified according to his deeds before God. And this is what Paul is essentially saying in the other verse you mentioned, Galatians 3:22, “But that no man is justified by the law in the sight of God…” So you see, there is no contradiction here.
Yes, faith indeed has to do with works, but only works of faith. If you want to further discuss on that issue, please let me know.
“Therefore, since we have been justified through faith, we have peace with God through our Lord Jesus Christ” (Romans 5:1)