Consider the equivalent problem using $y=x-\frac12$ on the interval $[-\frac12,\frac12]$: Prove that $ 4y^2=\frac13+\frac{4}{\pi^2}\sum_{n=1}^\infty(-1)^n\frac{\cos(2\pi ny)}{n^2}\tag{1} $ Since $\pi\csc(\pi z)$ has residue $(-1)^n$ at each integer, let's consider $f_y(z)=\pi\csc(\pi z)\frac{\cos(2\pi zy)}{z^2}$.
Let $\gamma_N$ be the rectangular path $ (N{+}\!\tfrac12)-iN\to(N{+}\!\tfrac12)+iN\to-(N{+}\!\tfrac12)+iN\to-(N{+}\!\tfrac12)-iN\to(N{+}\!\tfrac12)-iN $ It is not hard to see that for $|y|<\frac12$, $ \lim_{N\to\infty}\;\;\oint_{\gamma_N}f_y(z)\;\mathrm{d}z=0\tag{2} $ Equation $(2)$ relates the residue of $f_y$ at $0$ with the sum in $(1)$: $ \operatorname{Res}(f_y,0)+ 2\sum_{n=1}^\infty(-1)^n\frac{\cos(2n\pi y)}{n^2}=0\tag{3} $ Let's look at the Laurent series for $f_y$: $ \begin{align} \pi\csc(\pi z)\frac{\cos(2\pi zy)}{z^2} &=\left(\frac1z+\frac{\pi^2}{6}z+\dots\right)\left(\frac{1}{z^2}-2\pi^2y^2+\dots\right)\\ &=\frac{1}{z^3}+\left(\frac{\pi^2}{6}-2\pi^2y^2\right)\frac{1}{z}+\dots\tag{4} \end{align} $ Equation $(4)$ says that $\operatorname{Res}(f_y,0)=\frac{\pi^2}{6}-2\pi^2y^2$. Combining this with $(3)$ yields $ \sum_{n=1}^\infty(-1)^n\frac{\cos(2n\pi y)}{n^2}=\pi^2\left(y^2-\frac{1}{12}\right)\tag{5} $ which immediately verfies $(1)$.