Why do we need an invertible function to use $u$-substitution?

Beginning students (and symbolic algebra packages) have to beware.
Maple says if I take $$ \int_{-\pi}^{\pi} f(\sin \theta) \;d\theta \tag{1}$$ and change variables $s = \sin\theta$, I get $$ \int_0^0\frac{f(s)\;ds}{\sqrt{1-s^2}\;} = 0 \tag{2}$$ Of course $(1)$ can easily be nonzero.


Technically: Although Maple may think $\cos \theta = \sqrt{1-\sin^2\theta\;}$, in fact that is true on only part of the interval $[-\pi,\pi]$. On other parts of the interval, $\cos \theta = -\sqrt{1-\sin^2\theta\;}$


Invertibility is unnecessary. To quote the theorem statement in your link:

Let $\phi$ be a real function which has a derivative on the closed interval $[a,\,b]$. Let $I$ be an open interval which contains the image of $[a,\,b]$ under $\phi$. Let $f$ be a real function which is continuous on $I$. Then:$$\int_{\phi \left({a}\right)}^{\phi\left({b}\right)} f \left({t}\right) \ \mathrm d t = \int_a^b f\left({\phi \left({u}\right)}\right) \phi^\prime\left({u}\right) \mathrm d u.$$

$\phi$ being invertible is an important special case. If $\phi$ meets the above conditions but isn't invertible, we effectively have to add $\phi^\prime$ values. In this example, the values of $u$ consistent with a given value of $\phi(u)$ sum to $\phi+c$ for $c$ constant (proof is an exercise; note the symbols $\phi,\,u$ are changed respectively in that link to $u,\,x$). Thus the branches of $\phi^\prime$ sum to an invisible factor of $1$.

Now let's consider the example you asked about. The image of $[-\pi,\,\pi]$ under $\sin u$ is $[-1,\,1]$, so$$\int_{\sin(-\pi)}^{\sin\pi}f(t)dt=\int_{-\pi}^\pi f(\sin u)\cos udu$$if $f$ is continuous on an open interval $\supset[-1,\,1]$. In fact, both sides are $0$ for such $f$, since the left-hand side's limits are both $0$. By contrast, in @GEdgar's example something subtle happens. Let's write$$\int_{-\pi}^\pi f(\sin\theta)d\theta=\int_{-\pi}^{-\pi/2} f(\sin\theta)d\theta+\int_{-\pi/2}^{0} f(\sin\theta)d\theta+\int_0^{\pi/2} f(\sin\theta)d\theta+\int_{\pi/2}^\pi f(\sin\theta)d\theta.$$I split it into four pieces not because I wanted invertibility, but because expressing $\sin^\prime\theta=\cos\theta$ as a function of $\sin\theta$ gives a $\theta$-dependent $\pm$ sign in $\cos\theta=\pm\frac{1}{\sqrt{1-\sin^2\theta}}$. To wit,$$\begin{align}\int_{-\pi}^\pi f(\sin\theta)d\theta&=\int_0^{-1}\frac{-f(x)dx}{\sqrt{1-x^2}}+\int_{-1}^0\frac{f(x)dx}{\sqrt{1-x^2}}+\int_0^1\frac{f(x)dx}{\sqrt{1-x^2}}+\int_1^0\frac{-f(x)dx}{\sqrt{1-x^2}}\\&=2\int_{-1}^0\frac{f(x)dx}{\sqrt{1-x^2}}+2\int_0^1\frac{f(x)dx}{\sqrt{1-x^2}}\\&=2\int_{-1}^1\frac{f(x)dx}{\sqrt{1-x^2}}.\end{align}$$