I want to take the contour integral around 0. If I find the residue of the exponential, I get 2i. Multiplying by $2 \pi i$ and taking the real part I get $4 \pi$, which I believe is the correct answer. But the residue of $\frac{\cos 2z}{z^2}$ is 0, so the residue theorem would obviously give 0. What is the mistake I’m making?
Edit: I am trying to evaluate $\frac{\sin^2 z}{z^2}$ from 0 to infinity. I extended it to the entire axis and changed it into $\frac{1-\cos 2z}{z^2}$. I used the method where there is an infinite semi-circle and infinitesimal semi circle. The integral should evaluate to $\pi/2$, so I assumed by the residue theorem that the residue of $\frac{\cos 2z}{z^2}$ would be $2i$. I’m now lost on how to do this problem.
Edit 2: I think the problem is maybe in it being a semi-circle? We want the integral over the small semi-circle to be $\pi$, i.e., the integral over the whole circle to be $2 \pi$. With the residues, I’m getting the integral is 0. Being off by $2 \pi$ seems like it’s something that could be corrected in a step somewhere.
It is true that the residue of $\frac{\cos{(2z)}}{z^2}$ equals $0$. However, we don't use that residue in calculating $\int_{0}^{\infty}\frac{\sin^{2}\left(z\right)}{z^{2}}dz$. Based on your question, it seems like you're trying to evaluate this:
$$\oint_C \frac{\left(1-\cos\left(2z\right)\right)}{z^{2}}dz,$$
where $C$ is the contour you defined. When you evaluate the contour integral over the circumference, you have to use the Triangle Inequalities to bound the integrand so that using the Squeeze Theorem results in that integral over the circumference going to $0$. The reason the contour integral over $C$ would not help is that $\cos{(z)}$ is unbounded along the imaginary axis. From my experience, I made the mistake of thinking $|\cos{(z)}| \leq 1$ and tried using that to solve an improper integral only to be wrong because
$$\cos{(z)} = \frac{e^{iz}+e^{-iz}}{2} = \frac{e^x(\cos{(y)+i\sin{(y)}})+e^x(\cos{(y)}-i\sin{(y)})}{2} = \frac{1}{2}e^x\cos{(y)}.$$
Even though $|\cos{(y)}| \leq 1$, we know $e^x \to \infty$ as $x \to \infty$.
To use a more efficient contour integral, we instead evaluate
$$\oint_C \frac{1-e^{2iz}}{z^2}dz.$$
It seems like you're just trying to fit some puzzle pieces together without solving the contour integral. Just for the sake of trying to answer all your questions, I will prove that
$$\int_{0}^{\infty}\frac{\sin^{2}\left(z\right)}{z^{2}}dz = \frac{\pi}{2}.$$
Let $I$ be the given integral above. We can rewrite it as
$$\lim_{R\to\infty}\frac{1}{4}\Re\int_{-R}^{R}\frac{1-e^{2ix}}{x^2}dx.$$
Next, consider the contour $C$ defined exactly how you want it, except let's call the small semicircle curve $\gamma$ and the bigger circular curve $\Gamma$, and let's traverse it counterclockwise. Basically,
$$C = \left[-R,-\epsilon\right]\cup\gamma\cup\left[\epsilon,R\right]\cup\Gamma.$$
Let's also define $f(z) = \frac{1-e^{2iz}}{z^2}.$ One way to rewrite $\oint_C f(z)dz$ is by using a Cauchy Principal Value (P.V.) like this:
$$0 = P.V.\int_{-R}^{R}f(z)dz + \int_{\gamma}f(z)dz + \int_{\Gamma}f(z)dz.$$
It's a bit of grunt work, but hopefully, it's easy for you to prove $\int_{\Gamma}f(z)dz$ goes to $0$. As for the integral over $\gamma$, we get
$$\int_{\gamma}f(z)dz = -\pi i \operatorname{Res}(f(z), z=0) = -\pi i (-2i) = -2\pi.$$
Plug that answer back in, multiply by $\frac{1}{4}$ on both sides, and apply $R\to\infty$ and the real part on both sides to get $\frac{\pi}{2}$ as your final answer.