Galations is a hard letter to understand in English since it needs the Greek tenses to be understood properly. English versions often translate with tenses being reversed or not exact. The first thing to realize is much of it is talking about the Christian Walk after being saved. Once saved we are free from the law. Yet Galations says we are saved through law.
We are saved through law in Christ paying our legal penalty in his death. This was as legal as it gets. We ourselves are baptized through a law of faith. So whether Christ's work or our own it is law.
Galatians 2:19
For I through the law am dead to the law, that I might live unto God.
The Greek says it different leaving out the first the, it requires law to be dead to the law.
"for I through law am dead to the law"
It is through law that Christ gave his life and that we obey in baptism, this a spiritual law and not carnal. Yet, it is law.
This is how we die to the law. We die with Christ buried with him in baptism, afterward we are in freedom.
Paul was speaking of our justification and life after baptism. He wasn't refuting baptism. Galations 3:26-4:8 shows how we are adopted through faith when baptized. We receive the spirit of adoption. Then we walk in life free.
Galatians 4:7
Wherefore thou art no more a servant, but a son; and if a son, then an heir of God through Christ.
Through law we were made an heir of God, no longer in bondage as servants, Galations therefore supports baptism in salvation.Our freedom is after baptism. That is why Paul rebuked Peter for living contrary to the reality of freedom.
Galatians 2:14
But when I saw that they walked not uprightly according to the truth of the gospel, I said unto Peter before [them] all, If thou, being a Jew, livest after the manner of Gentiles, and not as do the Jews, why compellest thou the Gentiles to live as do the Jews?
We can also see this in Paul's own life, how he walked post salvation. Many confuse verses that may speak of before or after salvation.
Galatians 2:20
I am crucified with Christ: nevertheless I live; yet not I, but Christ liveth in me: and the life which I now live in the flesh I live by the faith of the Son of God, who loved me, and gave himself for me.
Most confusion stems over the verse speaking of before saved or after saved.
Galatians 2:17
But if, while we seek to be justified by Christ, we ourselves also are found sinners, [is] therefore Christ the minister of sin? God forbid.
The idea of seeking justification is ongoing, from salvation on. So, it is speaking of justification after baptism.