How to integrate $\int_0^\infty \left( \frac{\sin az}{z^2+1}\right)^2 dz$

The integral can be worked out without the residual theorem. Note

\begin{align} & I(a)=\int_0^\infty \left( \frac{\sin az}{z^2+1}\right)^2 dz\\ & I’(a)=\int_0^\infty \frac{z\sin(2az)}{(z^2+1)^2}dz \overset{IBP}= \int_0^\infty \frac{a\cos(2az)}{z^2+1}dz \end{align}

Next, let $J(b) = \int_0^\infty \frac{\sin(bz)}{z(z^2+1)}dz $ and

$$J’’(b) = \int_0^\infty \frac{\sin(bz)}{z(z^2+1)}dz - \int_0^\infty \frac{\sin(bz)}zdz =J(b) - \frac\pi2 $$

Solve to get $J(b) = \frac\pi2(1-e^{-b})$ and $I’(a) = a J’(b)|_{b=2a}=\frac\pi2a e^{-2a}$. Then $$I(a)= \int_0^a I’(s)ds = \frac\pi2 \int_0^a se^{-2s}ds= \frac\pi8-\frac\pi8(1+2a)e^{-2a} $$