If we take $x = \pi$, the right hand side becomes
$$\frac{\pi^2}{3} + \sum_{n=1}^\infty \frac{4}{n^2},$$
which is very convenient to determine $\sum\limits_{n=1}^\infty \frac{1}{n^2}$ provided we know what the Fourier series converges to for $x = \pi$.
If $f$ has a jump discontinuity at $x_0$, and is otherwise well-behaved in a neighbourhood of $x_0$ - I can't remember the criteria off the top of my head, but Lipschitz continuity is sufficient - then the Fourier series converges to the arithmetic mean of the one-sided limits of $f$ at $x_0$.
Here, we have
$$\lim_{x\to \pi^-} f(x) = \pi^2 + \pi\quad \text{and} \quad \lim_{x\to \pi^+} f(x) = \pi^2 - \pi,$$
so the arithmetic mean is $\pi^2$, and
$$\pi^2 = \frac{\pi^2}{3} + \sum_{n=1}^\infty \frac{4}{n^2}$$
easily yields
$$\sum_{n=1}^\infty \frac{1}{n^2} = \frac{\pi^2}{6}.$$
If we don't know the convergence behaviour of Fourier series at (nice enough) jump discontinuities, the best we can do is evaluate at $x = 0$. Then we obtain
$$0 = \frac{\pi^2}{3} + 4\sum_{n=1}^\infty \frac{(-1)^n}{n^2},$$
which we rearrange to
$$\frac{\pi^2}{12} = \sum_{n=1}^\infty \frac{(-1)^{n-1}}{n^2} = \sum_{n=1}^\infty \frac{1}{n^2} - 2\sum_{m=1}^\infty \frac{1}{(2m)^2} = \biggl(1 - \frac{2}{4}\biggr)\sum_{n=1}^\infty \frac{1}{n^2},$$
from which we again obtain
$$\sum_{n=1}^\infty \frac{1}{n^2} = \frac{\pi^2}{6}.$$