I was evaluating the integral
$$ \int 2x \cos(x^2)\,dx $$
and realised that it could be written in the form
$$ \int f'(g(x))g'(x)\,dx $$
and so substitution could be used to help evaluate it. Setting $u$ equal to $x^2$ (the inner function $g(x)$), we have
$$ du=2x\,dx $$
and so
$$ \int 2x \cos(x^2)\,dx=\int \cos(u)\,du=\sin(u)+C=\sin(x^2)+C $$
However, it appears that making the wrong substitution $u=2x$ still works, even though $u$ is not equal to the inner function $g(x)$:
$$ u=2x \implies du=2\,dx \\ \int 2x \cos(x^2)\,dx=\int\frac{u}{2}\cos\left(\frac{u^2}{4}\right) $$
Admittedly, solving this is ugly. In fact, it requires two more substitutions, and so it was clearly a bad idea to set $u=2x$. However, the final answer did indeed come out as $\sin (x^2)+C$. My question is about why this works at all. If I understand correctly, substitution is only a valid method when $u=g(x)$, as this justifies the treating of $du$ and $dx$ as manipulable terms. We know that
$$ \int f'(u)\,du=f(u)+C=f(g(x))+C $$
Therefore,
$$ \int f'(u)\,du = \int f'(g(x))g'(x)\,dx=\int f(g(x))+C $$
meaning that $g'(x)\,dx$ can be 'replaced' by $du$. If $u\neq g(x)$, then this method seems to fall apart. Despite this, setting $u=2x$ actually did end up working. Was this just a coincidence?
Note that in the link you provided, the calculator sets $v=u^2=4x^2$ and then $w=v/4=x^2$, i.e. effectively it has substituted for $x^2$ only albeit in a more circuitous manner.