The epistle of James was written to Jewish Christian believers. Some might have been trying to still follow the law of Moses. Knowing and understanding this context is vital to understanding some of the things James writes about the law. Such as this verse from James 2.
If you really keep the royal law found in Scripture, “Love your neighbor as yourself,” you are doing right.
James 2:8 (NIV)
James isn’t telling people they need to follow the law. Instead, James points out that anyone who says they are following the law should follow this one, “loving your neighbor as yourself.” However, they are breaking the law if they’re not doing that. Thus, anyone who shows favoritism isn’t following the law and is guilty of breaking all the rules.
James says something about keeping the law in James 4:11.
Brothers and sisters, do not slander one another. Anyone who speaks against a brother or sister or judges them speaks against the law and judges it. When you judge the law, you are not keeping it, but sitting in judgment on it.
James 4:11 (NIV)
As in James 2:8, James is not advocating that people follow the law here. He’s pointing out to those who might want to follow the law that when they are self-righteous and criticize another Christian, they are breaking the law. Furthermore, when someone points out that someone isn’t doing something and it’s not even in the law, they are judging the law. They are saying the law is short-sighted because it didn’t include this or that thing, so they include it themselves.
The notion that we know better than God and are better than others is the chief danger of self-righteousness and hypocrisy. When all have sinned and fallen short of the grace of God.
Thus we can see that when James talks about following the law, he’s not telling people they need to follow it. Instead, James points out how people fail to follow the law through what they do or don’t do.