This question is answered very completely by numerous commentators of which I will quote just two below. Paul is here discussing the judaizing people who wanted to attain God's favor by keeping the law which cannot be done.
Ellicott says this:
(21) In thus attaching himself devotedly to Christ, the Christian
escapes the charge of refusing and thwarting the free gift of
justification which God has offered to him in His Son. He has made his
choice of Christ, and not of the Law. On the other hand, if he had
chosen the Law, and gone to it, and not to Christ, in his search for
righteousness, he would have practically declared the death of Christ
to be a useless and unnecessary sacrifice.
Frustrate.—An exactly literal translation of the Greek word, which means “to render nugatory or ineffectual.” The grace of God goes forth
with a certain mission to perform; but the Judaising party, by still
clinging to the Law, prevented it from taking effect, and made it
“return void” unto its Giver.
If righteousness come by the law.—What all men seek is justification in the sight of God. This is given to the just or
righteous. But there were two ways of becoming thus just or righteous.
The Law professed to make righteous those who complied with its
provisions. But this was only a profession, for no one could really
keep the Law. The Christian, therefore, rightly falls back upon faith
in Christ, which brings him both an imputed righteousness, and also,
in part, at least, a real righteousness. A deep and genuine faith in
Christ is allowed to atone for the many unavoidable breaches of the
Law, and that faith by degrees operates a real and vital change in the
character and life of the man.
Barnes says this:
I do not frustrate the grace of God - The word rendered "frustrate"
(ἀθετῶ athetō) means properly to displace, abrogate, abolish; then
to make void, to render null; Mark 7:9; Luke 7:30; 1 Corinthians 1:19.
The phrase "the grace of God," here refers to the favor of God
manifested in the plan of salvation by the gospel, and is another name
for the gospel. The sense is, that Paul would not take any measures or
pursue any course that would render that vain or inefficacious.
Neither by his own life, by a course of conduct which would show that
it had no influence over the heart and conduct, nor by the observance
of Jewish rites and customs, would he do anything to render that
inefficacious. The design is to show that he regarded it as a great
principle that the gospel was efficacious in renewing and saving man,
and he would do nothing that would tend to prevent that impression on
mankind. A life of sin, of open depravity and licentiousness, would do
that. And in like manner a conformity to the rites of Moses as a
ground of justification would tend to frustrate the grace of God, or
to render the method of salvation solely by the Redeemer nugatory.
This is to be regarded, therefore as at the same time a reproof of
Peter for complying with customs which tended to frustrate the plan of
the gospel, and a declaration that he intended that his own course of
life should be such as to confirm the plan, and show its efficacy in
pardoning the sinner and rendering him alive in the service of God.
For if righteousness come by the law - If justification can be secured
by the observance of any law - ceremonial or moral - then there was no
need of the death of Christ as an atonement. This is plain. If man by
conformity to any law could be justified before God, what need was
there of an atonement?