Rom 4: 2-5
For if Abraham was justified by works, he has something to boast about, but not before God. For what does the Scripture say? “Abraham believed God, and it was counted to him as righteousness.” Now to the one who works, his wages are not counted as a gift but as his due. And to the one who does not work but believes in him who justifies the ungodly, his faith is counted as righteousness.
James 2: 21-23
Was not Abraham our father justified by works when he offered up his son Isaac on the altar? You see that faith was active along with his works, and faith was completed by his works; and the Scripture was fulfilled that says, “Abraham believed God, and it was counted to him as righteousness”—and he was called a friend of God.
On the cursory reading of these 2 passages, they seem to contradict each other. But if we delve further into the wider context of these 2 passages, we will soon realize that the Works mentioned are different. I will call the Works in Romans as Law-works while that in James as Faith-works.
In Romans, Paul was addressing the Jews who might still be trying to earn their salvation by law-works in keeping the Halakha, the Jewish Law, which includes 613 prohibitions so devised as to comply with the Mosaic Law, the Ten Commandments. But we read in Phil 3:4-6 that Paul could be blameless in keeping this Jewish Law like many Pharisees at that time and yet he persecuted the church. The Pharisees could keep the Jewish Law meticulously yet their hearts were not repentant – they were lovers of money, mean-spirited and self righteous. They could go through the physical circumcision meticulously but their hearts were not circumcised.
In James, James was not talking about keeping this Jewish Law but about Action or Faith-works which will prove that Faith is legitimate. He quoted 2 examples of legitimate faith in Abraham and Rahab. One was about to perform child sacrifice and the other committed treason – not good works exactly. But their action proved that they believed God and it was counted to them as righteousness.