Let's expand on @Chiral Anomaly's answer via taking a look at a concrete example.
In 2D, one would have the traceless property:
$$
\sum_\mu\gamma^\mu\gamma^\sigma\gamma_\mu = 0
$$
which can be verified easily, e.g.
$$
\sum_\mu\gamma^\mu\gamma^0\gamma_\mu=\gamma^0\gamma^0\gamma_0 + \gamma^1\gamma^0\gamma_1 = (\gamma^0\gamma_0)\gamma^0 - (\gamma^1\gamma_1)\gamma^0= \gamma^0- \gamma^0 = 0
$$
This identity is representation-independent, since it only invokes the anti-commuting properties of the Gamma matrices. The identity can be extended to any vector $l = \sum_\sigma l_\sigma \gamma^\sigma$:
$$
\sum_\mu\gamma^\mu l\gamma_\mu = 0
$$
The identity implies that the QED vacuum polarization is traceless:
$$
\sum_{\mu\nu}\Pi^{\mu\nu}(p)g_{{\mu\nu}} \sim \sum_{\mu\nu}\int_l Tr\left(\gamma^\mu\frac{1}{\not l}\gamma^\nu\frac{1}{\not l+\not p}\right)g_{{\mu\nu}} = \int_l \frac{Tr\left(\sum_{\mu}\gamma^\mu{\not l}\gamma_\mu({\not l+\not p})\right)}{l^2(l+p)^2} = 0
$$
But for 2D massless QED (Schwinger model), it turns out that a Ward identity compatible vacuum polarization is NOT traceless
$$
\sum_{\mu\nu}\Pi^{\mu\nu}(p)g_{{\mu\nu}} \sim \sum_{\mu\nu}(g^{{\mu\nu}} - \frac{p^\mu p^\nu}{p^2})g_{{\mu\nu}} = 2 - \frac{p^2}{p^2} = 1 \neq 0
$$
Confused? Welcome to the wonderful QFT club which is purportedly self-consistent!
Hint:
$$
0*\infty \neq 0
$$
Infinities and dimensional regularization can do magic whereby Ward identity
$$
\sum_{\nu}p_\nu \Pi^{\mu\nu}(p) \sim p^{{\mu}} - \frac{p^\mu p^2}{p^2}=0
$$
is preserved at the cost of tracelessness.
For $D=4$, let's say you want to calculate $\sum_\mu\text{trace}(X\gamma^\mu Y\gamma_\mu)$, and Y can be expressed as:
$$
Y = AI + B^\mu\gamma_\mu + C^{\mu\nu}\gamma_\mu\gamma_\nu + D^\mu\gamma_\mu \gamma_5 + E \gamma_5,
$$
then
$$
Y' := \sum_\mu\gamma^\mu Y\gamma_\mu \\
=4AI -2 B^\mu\gamma_\mu +2 D^\mu\gamma_\mu \gamma_5 -4E \gamma_5.
$$
Note that the antisymmetric portion $C^{\mu\nu}\gamma_\mu\gamma_\nu$ drops out for $D=4$, as opposed to vector portion dropping out in 2D.
The last step is to calculate:
$$
\sum_\mu\text{trace}(X\gamma^\mu Y\gamma_\mu)= \text{trace}(XY')
$$