Some Background on Integration by Substitution
It is important to understand the assumptions one makes in Integration by Substitution.
Let $I$ denote the integral given by $I=\int_a^b f(x)\,dx$.
Condition $(i)$:
We assume that $f$ is continuous on $[a,b]$.
Condition $(ii)$:
The inverse function $u^{-1}$, of $u(x)$ is continuously differentiable on $[u(a),u(b)]$.
Under Conditions $1$ and $2$, we have
$$\begin{align}I=&\int_a^b f(x)\,dx\\\\&=\int_{u(a)}^{u(b)}f(u^{-1}(t))\frac{du^{-1}(t)}{dt}\,dt \tag 1\end{align}$$
Note that the relationship expressed in $(1)$ can be obtained formally through the substitution $u(x)=t$, under Assumptions $(i)$ and $(ii)$.
Application to Evaluating $\int_0^\pi \frac{1}{a^2\sin^2(x)+b^2\cos^2(x)}\,dx$
To apply the substitution in $(1)$ correctly to evaluate the integral of interest, one must ensure that both $(i)$ and $(ii)$ are satisfied.
Since $f(x)=\frac{1}{a^2\sin^2(x)+b^2\cos^2(x)}$ is continuous for $x\in [a,b]$ and Condition $1$ is satisfied.
The substitution used in the reference cited in the OP is $\tan(x)=t$. Note that for $x\in [0,\pi]$ the inverse function for the tangent function is given by
$$\tan^{-1}(t)=\begin{cases}\arctan(t)&, t>0\\\\\pi+\arctan(t)&,t<0 \tag 2\end{cases}$$
where the $-\pi/2 < \arctan(x)<\pi/2$ is the principal branch of the inverse tangent function. The inverse tangent is not even continuous at $0$ and we cannot apply, therefore, the substitution over the interval $x\in [0,\pi]$.
Instead, we can write the integral as the sum
$$\begin{align}
\int_0^\pi f(x)\,dx&=\lim_{\epsilon \to 0^+}\left(\int_0^{\pi/2-\epsilon}f(x)\,dx+\int_{\pi/2+\epsilon}^\pi f(x)\,dx\right)
\end{align}$$
where $f(x)=\frac{1}{a^2\sin^2(x)+b^2\cos^2(x)}$.
The inverse tangent function $\tan^{-1}(x)$ as expressed in $(2)$ is continuously differentiable on each separate interval $x>0$ and $x<0$ and so, Condition $2$ is satisfied on each separate interval.
Then, we can write
$$\begin{align}\lim_{\epsilon \to 0^+}\int_0^{\pi/2-\epsilon}f(x)\,dx&=\int_0^{\infty}f(\arctan(t))\frac{1}{1+t^2}\,dt\\\\
\lim_{\epsilon \to 0^+}\int_{\pi/2+\epsilon}^\pi f(x)\,dx&=\int_{-\infty}^0f(\pi+\arctan(t))\frac{1}{1+t^2}\,dt \tag 3
\end{align}$$
Since $f(x)$ is even and $\pi$-periodic, then the second equality in $(3)$ is identical to the first. Therefore, we have
$$\begin{align}
\int_0^\pi f(x)\,dx&=2\int_0^\infty \frac{f(\arctan(t))}{1+t^2}\,dt\\\\
&=2\int_0^\infty \frac{1}{a^2t^2+b^2}\,dt\\\\
&=\left. \frac{2\arctan(at/b)}{ab}\right|_{0}^{\pi/2}\\\\
&=\frac{\pi}{ab}
\end{align}$$