WEB Gal 5:4 You are alienated from Christ, you who desire to be justified by the law. You have fallen away from grace.There's a huge difference between studying (and even keeping! see Acts 21:21-24) the law and desiring to be justified by keeping that law.
Paul kept the law (as did thousands of other Jewish believers, zealously - Acts 21:21-24), but he did not seek to be justified by that keeping of the law; he was justified by his faith in Christ.
Seeking to be justified by anything other than faith in Christ (whether that be by keeping the Law of Moses, or keeping the sub-set of that Law known as the Ten Commandments, or keeping the supposed law of the Five-Step Plan of Salvation, etc) is to fall from grace which Jesus bestows upon those who trust in him (as opposed to those who trust in their own right-ness in keeping some "law"); this doctrine is the other gospel about which Paul warns four chapters earlier (Gal 1:6ff).
Paul spends chapter two of Galatians explaining how it took a major conference with the elders and apostles in Jerusalem to conclude that Gentiles were not required to keep the law (detailed in Acts 15), because law-keeping (either by Jews or Gentiles) is not the way to justification. Justification is by faith, and justification by law-keeping is "another gospel".
Paul spends chapter three of Galatians explaining that Abraham was justified when he believed, before he acted, and that no man is justified by law, and that trying to keep the law is a curse, because no one can do it (you must live by the rules perfectly or you're a law-breaker; only Jesus did that perfectly, and he became that curse for us). So who are the blessed now? The ones who seek to be justified by law-keeping? No. The ones who are blessed are those who are of faith with the faithful Abraham, who was declared right when he had faith, before he did any right action. (Note that his faith was not a dead faith; it was a working faith, that drove him to do right actions; it was not a faith without works, but rather a faith before works, as opposed to the faith of demons, which has no works other than to make those demons tremble - Jam 2.)
Paul spends chapter four of Galatians explaining how that keeping rules and regulations are merely worldly, "miserable elemental principles", a form of "bondage" (v. 9-10). He tells the Colossians the same thing, but in more detail even (see Col 2:16ff).
Paul then wraps up in chapter five of Galatians, telling his readers to stand firm in liberty, not becoming again entangled with a yoke of bondage; if you keep law, you have to keep all of it. And if you go that route, seeking to be justified by keeping some law, any law, not just the Mosaic Law, you are fallen from grace. The "law" you are to fulfill is this - "You shall love your neighbor as yourself" (v. 14). (He repeats himself a chapter later, emphasizing that "the law of Christ" is fulfilled by bearing one another's burdens - 6:2.) Walk by the spirit, not by the law. (He says in another place that we are to serve in the newness of the spirit, not in the oldness of the letter - Rom 7:6; and that his team are servants of a covenant, not of the letter, but of the spirit - 2 Cor 3:6; and that the true Jew is one who is circumcised in the spirit, not the letter - Rom 2:29.)
Paul finishes out his letter in chapter 6 of Galatians by pointing out that even the law-keepers fail to keep the law - 6:13.
Yet even though Paul is adamant that we are saved by faith rather than by law-keeping, he himself walked according to the law (Acts 21:24), and he upholds the law (Rom 3:31), and says it's holy (Rom 7:12) and good (7:16).
Paul makes a huge distinction between keeping the law as something good to keep, and keeping it in order to be justified by keeping it. We, too, should make that distinction.