Substitution Makes the Integral Bounds Equal
For the second integral, note that the substitution $u=\sqrt{x^2+a^2}$ implies: $$ u\ge 0 \quad \mbox{and}\quad x=\pm\sqrt{u^2-a^2} $$ so:
$$ dx=\frac{udu}{\sqrt{u^2-a^2}} \mbox{for}\quad x \ge 0 $$
$$ dx=\frac{udu}{-\sqrt{u^2-a^2}} \mbox{for}\quad x < 0 $$
and the integral splits in two parts as $\int_{-b}^0 +\int_0^b$. This gives the correct result.
We have an analogous situation for the first integral with the substitution $$ u=\sin x \qquad \cos x=\pm \sqrt{1-u^2} $$
The first integral is NOT zero! Let $f$ be the identity function, for example.
In the second integral it is wrong to say that $x=\sqrt{u^2-a^2}$ for all values of $x$. In the first integral, the same: $cos(x)=\sqrt{1-u^2}$ is not true for all values of $x$.
When the substitution is not injective, problems arise when you try to express the integrand in terms of the new variable, as it can be seen from this examples. So always split the integration domain so that there is injectivity in each part.