Here's a complex analysis proof. For $|\theta|\leq\pi,$ we have that $$ F(t)=\frac{\cos(\theta t)\pi}{\sin (\pi t)} $$ is an odd meromorphic function for $t\in\mathbb{C}$ with simple poles at $k\in\mathbb{Z}$, which moreover is bounded as $|\Im t|\to\infty$. We claim that the series in brackets $$ G(t)=\frac{1}{t} + 2t \sum_{k=1}^\infty (-1)^k \frac{\cos(k\theta)}{t^2 - k^2} $$ has all the same properties. Indeed, we have $$ \left|(-1)^k\frac{\cos (k\theta)}{t^2-k^2}\right|\leq \frac{1}{|(\Re t)^2-(\Im t)^2-k^2|}\leq \frac{2}{(\Im t)^2+k^2}, $$ if either $(\Im t)^2\geq 2(\Re t)^2$, or $k^2\geq 2(\Re t)^2$. From the latter case, the series converges absolutely and uniformly on compact subsets of $\mathbb{C}\setminus \mathbb{Z}$, and the former case can be used to show, e.g., by comparing with the integral, that $|G(t)|$ is bounded as $|\Im t|\to \infty$. The poles at $\pm k$ only come from $k$-th term. Now we simply note that $F$ and $G$ have the same residues at the poles, so $F-G$ is a bounded holomophic function in the whole plane $\mathbb{C},$ hence $F-G$ is constant by Liouville's theorem. Since $F-G$ is odd, the constant is zero. If $\theta>\pi$, then $F(t)$ is no longer bounded as $t\to\infty$, while the RHS still is, so the equality cannot hold. As noted by Conrad in the comments, the RHS does not change under replacing $\theta\mapsto \theta+2\pi m$, so by choosing an appropriate $m$ we can reduce this to the previous case.