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 over $|\Im t|\geq 10$, say. 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 holomophic function in the whole plane $\mathbb{C}.$ It is enough to show that $F-G$ is bounded, then it is constant by Liouville's theorem, and since it is odd, the constant is zero.
To check boundedness, by maximum principle, it suffices to upper-bound $|F|$ and $|G|$ separately on the boundary of each box $$R_m=\left\{m-\frac12<\Re t<m+\frac12,|\Im t|\leq 10\right\},$$ by a constant independent of $m$. For $F$, we just upper-bound $|\cos t\theta|\leq e^{10|\theta|}$ and lower-bound $\sin(\pi t)$ by its minimum (which is independent of $m$ by periodicity). For $G$, we notice that we can actually write, for any $m$, \begin{multline} G(t)=\lim_{N\to\infty}\sum_{k=-N}^N(-1)^k\cos(k\theta)\frac{1}{t-k}=\lim_{N\to\infty}\sum_{k=-N+m}^{N+m}(-1)^k\cos(k\theta)\frac{1}{t-k}\\=\frac{(-1)^m}{t-m}+2(t-m)\sum_{k=1}^\infty(-1)^{k-m}\frac{\cos((k-m)\theta)}{(t-m)^2-k^2}, \end{multline} and bounding the absolute value term by term, as above, on the boundary of $R_m$, yields an estimate independent of $m$.
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.