Note that for fixed non-integer $u$,
\[f(z)=\frac{\pi\cot\pi z}{(u+z)^2}\]
has a pole of order 2 at $z=-u$ and simple poles at $z=n$ for each $n\in\mathbb{Z}$. Therefore, the residues are
\[\begin{aligned}\text{res}_{-u}f(z) &=\lim_{z\to-u}\frac{\,d}{\,dz}\left[\pi \cot\pi z\right]\\ &=-\frac{\pi^2}{\sin(\pi u)}\end{aligned}\]
and
\[\begin{aligned}\text{res}_nf(z) &=\lim_{z\to n}(z-n)\frac{\pi\cot\pi z}{(u+z)^2}\\ &=\lim_{z\to n}(z-n)\frac{\pi\cos\pi z}{(u+z)^2\sin\pi z}\\ &= \lim_{z\to n}\frac{\pi(z-n)}{\sin(\pi(z-n))}\frac{\cos(\pi(z-n))}{(u+z)^2}\\ &=\frac{1}{(u+n)^2}.\end{aligned}\]
Thus, by the residue theorem, we get
\[\int_{|z|=N+1/2}\frac{\pi \cot\pi z}{(u+z)^2}\,dz=-\frac{\pi^2}{\sin^2(\pi u)}+\sum_{n=-\infty}^{\infty}\frac{1}{(u+n)^2}\]
In order to establish the identity, we need to show that
\[\int_{|z|=N+1/2}\frac{\pi \cot\pi z}{(u+z)^2}\,dz\rightarrow 0\]
as $N\rightarrow\infty$.
There exists a positive integer $N_0$ such that for $N\geq N_0$, the conditions $|z|=N+\tfrac{1}{2}$ and $|\text{Im}z|\leq 1$ imply that the distance from $\text{Re}z$ to the nearest integer is $\geq\tfrac{1}{4}$. Since $\cot\pi z$ has period $1$ and its poles occur only at the integer values, it is uniformly bounded on $\{z:|\text{Im}z|\leq 1\text{ and }|\text{Re}z-n|\geq\tfrac{1}{4}\}$. When $z=x+iy$ with $y\geq 1$, it follows that
\[\cot(\pi z)=i\frac{e^{2iz}+1}{e^{2iz}-1}\]
and
\[|\cot(\pi z)|\leq\frac{1+e^{-2y}}{1-e^{-2y}}\leq\frac{1+e^{-2}}{1-e^{-2}}.\]
Similarly, when $z=x+iy$ and $y\leq -1$, it follows that
\[\cot(\pi z)=i\frac{1+e^{-2iz}}{1-e^{-2iz}}\]
and
\[|\cot(\pi z)|\leq\frac{1+e^{2y}}{1-e^{2y}}\leq\frac{1+e^{-2}}{1-e^{-2}}.\]
Therefore,
\[M=\sup_{N\geq N_0}\sup_{|z|=N+\tfrac{1}{2}}|\cot(\pi z)|<\infty.\]
Thus,
\[\int_{|z|=N+\tfrac{1}{2}}f(z)\,dz\leq \frac{M}{\left(N+\tfrac{1}{2}\right)^2-|u|^2}\cdot 2\pi\left(N+\tfrac{1}{2}\right)\]
for $N\geq N_0$ and $N\geq |u|$. This now implies that
\[\int_{|z|=N+\tfrac{1}{2}}f(z)\,dz\rightarrow 0\]
as $N\rightarrow\infty$. Therefore,
\[-\frac{\pi^2}{\sin^2(\pi u)}+\sum_{n=-\infty}^{\infty}\frac{1}{(u+n)^2}=0\implies \sum_{n=-\infty}^{\infty}\frac{1}{(u+n)^2} = \frac{\pi^2}{\sin^2(\pi x)}\]
and the proof is complete. Q.E.D.