Extend the sum $S$ to
$$ 2S-1 = \sum_{n=-\infty}^{\infty} \frac{(-1)^n}{n^2+1}, $$
which we can get away with because the summand is even in $n$. We want to find something that gives these as residues, then use Cauchy's theorem, hoping the integral goes to zero. Therefore we take
$$ \frac{\pi\csc{\pi z}}{z^2+1}: $$
this has poles at $z=n$ with residue $ (-1)^n/(n^2+1) $, and two others, at $\pm i$, with residues $ \frac{\pi \operatorname{csch}{(\pm \pi)}}{\mp 2i} $. Also, if we take the integral to be around a large square that between the poles, one can show using $ \lvert\sin{(x+iy)} \rvert^2 = \sin^2{x}+\sinh^2{y} $ and the corresponding one for cosine that the integrand is bounded on the border of the square by a multiple of $1/(x^2+y^2)$, and hence the integral tends to zero as we make the square larger and larger. Hence
$$ \frac{1}{2\pi i}\left( 2S_k-1 - \frac{2\pi\operatorname{csch}{\pi}}{2} \right) = \int_{\square_k} \frac{\pi\csc{\pi z}}{z^2+1} \, dz \to 0 $$
as $k \to \infty$, and then you can rearrange to get the answer.
The general idea is that $\pi\cot{\pi z}$ has residue $1$ at every integer $n$, while $\csc{\pi z}$ has residue $(-1)^n$ at every integer $n$. The same technique works on any sum of the form $1/p(n^2)$ (or $(-1)^n/p(n^2)$) where $p$ is a nonconstant polynomial, although you do have to find the roots.