In a literal sense, the priests did violate the Sabbath because they worked and earned their living on the Sabbath, see Ex 20:8-11, Deut 5:12-15 that prohibited regular work on the weekly Sabbath.
In a strict legal sense, they did not violate the Sabbath because the same series of Torah laws required the priests to do such things to maintain the temple services and ritual. See the many rules about what priest were supposed to do on Sabbath such as sacrifices (Num 28:9, 10) and ceremonial rites (Ex 25:30, Lev 24:7, 8) and judicial components (Ex 31:14, 15, 35:2, Num 15:32-36).
Thus Jesus is (predictably) correct in saying:
Matt 12:5 - Or haven’t you read in the Law that on the Sabbath the
priests in the temple break the Sabbath and yet are innocent?
Benson correctly observes:
Matthew 12:5-6. Have ye not read in the law, &c. — He does not mean
that the words following were to be found in the law, but only that
they might read in the law, how the priests were obliged, on the
sabbath days, to perform such servile work in the temple as,
considered separately from the end of it, would have been a
profanation of the sabbath, but really was not so, because it was
necessary to the public worship of God, on account of which the
sabbath was instituted. If it be asked what servile work the priests
performed on the sabbath, the answer is obvious. On that day, as well
as on other days, they made up the fires, killed, flayed, and dressed
the sacrifices, and performed other pieces of manual labour necessary
to the religious service which God had established among them. Nay,
besides the continual burnt offering, the priests were obliged, on the
sabbaths, to sacrifice two lambs extraordinary, by which their servile
work was that day double of what it was on the other days of the week.
See Numbers 28:9. But in this place is one greater than the temple —
As if he had said, “If you reply that the priests were not culpable in
those actions, because they were undertaken for the temple service, I
acknowledge it; but at the same time I must observe, that if the
temple, with its service, is of such importance as to merit a
particular dispensation from the law of the sabbath, I and my
disciples, whose business of promoting the salvation of men is a
matter of more importance, may, on that account, with more reason take
the same liberty in a case of the like necessity. According to this
interpretation, the reading μειζον, a greater work, instead of μειζων,
a greater person, which is authorized by many manuscripts, will have a
peculiar elegance. Then the sense will be, ‘There is here a much more
noble work carrying on than the temple service.’” — Macknight.