My attempt: The poles are $z=1,-1$, both lie inside the rectangle.
Residue at the poles are $-\frac12$ each, since residue at $$f(a)=\left[\frac{\cos \pi z}{\frac{d}{dz}(z^2+1)}\right]_{z=a}=\frac{\cos\pi a}{2a}.$$
So, by residue theorem,
$$\int \dfrac{\cos\pi z}{z^2-1}\, dz= 2\pi i \left[-\frac{1}{2}-\frac{1}{2}\right]=-2\pi i.$$
Is this correct?
The residue of $\frac{\cos(\pi z)}{z^2-1} =\frac{h(z)}{z-1}, \ h(z) = \frac{\cos(\pi z)}{z+1}$ at $z = 1$ is $h(1)=\frac{\cos(\pi)}{2} = -1/2$.
The residue of $\frac{\cos(\pi z)}{z^2-1} =\frac{H(z)}{z+1}, H(z) = \frac{\cos(\pi z)}{z-1}$ at $z = -1$ is $H(-1) = 1/2$.
The proof of the residue theorem in the case of finite contours and poles of order $1$ is not complicated :
$g(z) = f(z) - \frac{-1/2}{z-1}- \frac{1/2}{z+1}$ is holomorphic (on a simply connected open containing the contour) so the Cauchy integral theorem applies : $\int_C g(z)dz =0$
and $$\int_C f(z)dz = \int_C (\frac{-1/2}{z-1}+ \frac{1/2}{z+1})dz = 2i \pi (-1/2+1/2) = 0$$
(for evaluating $\int_C \frac{1}{z-a}dz$, use that when choosing the correct branch for the logarithm : $\frac{d}{dz}\log(z-a) = \frac{1}{z-a}$)