Galatians appears to be Paul's "hot take" on the Law. Galatians is an extraordinarily emotional letter, a bit unhinged at times. The crisis was that some teachers had come to Paul's churches in Galatia and had begun preaching a gospel that demanded that Paul's Gentile converts be circumcised and begin observing the Torah (at least parts of it). For Paul, this was a repudiation of the work of the Messiah, whose work is embraced though faith.
In making this contrast between his gospel and the "false gospel" that had shown up in his churches, Paul says some very extreme things about the Law. Mincing no words, Paul describes the Law as an enslaving power, and places it alongside other demonic powers that hold humanity captive. For example,
Galatians 3.23, 4.8-9That's a pretty extreme view. So much so, Paul seems to have reconsidered his "hot take" by the time we get to Romans. Maybe Paul's view regarding the Law didn't change, but his treatment in Romans is much more nuanced.
Now before faith came, we were held captive under the law, imprisoned until the coming faith would be revealed.
Formerly, when you did not know God, you were enslaved to those that by nature are not gods. But now that you have come to know God, or rather to be known by God, how can you turn back again to the weak and worthless elementary principles of the world, whose slaves you want to be once more?
Specifically, in Romans Paul is keen to observe that the law is holy, righteous and good: "So the law is holy, and the commandment is holy and righteous and good." (Romans 7.12)
So the problem with the Law in Romans isn't with the Law exactly, but with how the power of Sin seizes an opportunity through the Law: "For sin, seizing an opportunity through the commandment, deceived me and through it killed me." (Romans 7.11)
In short, in Galatians the Law seems to be the enslaving power. But by the time we get to Romans, however, Paul seems to have reconsidered that opinion, or at least clarified his position. The problem isn't with the Law but with how Sin seizes an opportunity through the Law.
More simply, in Galatians the problem is the Law. In Romans the problem is the power of Sin.