On Paul's Math Notes covering Trig Substitutions for Integrals we start with an integral:
$$\int{{\frac{{\sqrt {25{x^2} - 4} }}{x}\,dx}}$$
Right away he says to substitute $x=\frac{2}{5}\sec(θ)$. Why is that allowed?
Looking further down onto how he approaches the problem, it seems like it's allowed because it's compensated for with a dx:
$$dx = \frac{2}{5}\sec \theta \tan \theta \,d\theta$$
Is that what's going on here? It's fair to say you can substitute x with whatever you want so long as you update dx? Seems like it wouldn't work for constant functions of x, like $x = 5$.. since that'd get you $dx=0$ and clearly be wrong. So what rules are in play here for substitution?
The exact rule is: if $x(t)$ is a differentiable function of $t$, then for any continuous integrand $f(t)$, $$ \int f\big( x(t) \big) x'(t)\,dt = \bigg( \int f(x)\,dx \bigg) \bigg| _{x=x(t)}, $$ where the subscript on the right-hand side means that after the indefinite integral $\int f(x)\,dx$ is evaluated, one then plugs in $x(t)$ for $x$. This can be proven easily by differentiating both sides with respect to $t$—the right-hand side is a composition of two functions, with the inner function being $x(t)$, by the definition of the notation.
You're interested in the situation where we start from the right-hand side and choose the function $x(t)$ (as opposed to the more standard substitution method where one starts from the left-hand side); in particular you're asking what happens if you set $x=5$ for example. Then the left-hand side is $\int 0\,dt = C$, while if $F(x)$ is an antiderivative of $f(x)$ then the right-hand side is $\big(F(x)+C'\big)\big|_{x=5}$, which is simply $F(5)+C'$. Since $C$ and $C'$ represent arbitrary constants and $F(5)$ is some constant, these two answers represent the same family of functions. It's not wrong after all—just not useful!