Integrating $\int_0^\infty \frac{1-\cos x }{x^2}dx$ via contour integral.
The singularity is removable for the function you want to integrate but not for their $f(z).$
The motivation for the question seems to be: Why does the author integrate $f(z)=(1-e^{iz})/z^2$ over the complex plane, rather than the original integrand $g(z)=(1-\cos z)/z^2$ ? You're right that $g$ is an entire function, and it could be integrated over a semicircle without having to dodge the origin.
However, the integral of $g$ over the arc $\gamma_R^+$ doesn't obey a nice bound. While integrating $f$, the author needs the inequality $$ \left|\frac{1-e^{iz}}{z^2}\right|\leq\frac{2}{|z|^2}, $$ which is justified by the fact that $|e^{iz}|\leq 1$ for $z$ in the upper half-plane. The same can't be said for $\cos z=(e^{iz}+e^{-iz})/2$; instead, the $e^{-iz}$ term is large in the upper half-plane. That's why $g$ is less convenient than $f$.