The following is a solution of the differential equation $y'' = y$ with initial values $y(0) = 3$, $y'(0) = 1$. Considering $y$ to be a function of $x$ and omitting some standard details:
Let $z = y'$. Then $y'' = \frac{dz}{dx} = \frac{dz}{dy} \frac{dy}{dx} = z \frac{dz}{dy}$. Substituting, $z\frac{dz}{dy} = y$ is separable with initial value $y = 3$, $z = 1$, so has the unique solution $z = \sqrt{y^2 - 8}$. Now the equation $y' = \sqrt{y^2 - 8}$ with initial value $y(0) = 3$ has solution $y = 2e^x + e^{-x}$, which is also a solution to the original problem.
While this does produce the correct answer, the step using $\frac{dz}{dy}$ is unjustified. One way to fill this gap is to note that since $y'(0) \ne 0$, the inverse function theorem says that locally $x$ and therefore $y'$ is in fact a (smooth) function of $y$. This is somewhat implicitly used in picking the positive branch of the square root $\sqrt{y^2 - 8}$.
But I do not know how to justify the definition of $z$ as a function of $y$ and therefore of $\frac{dz}{dy}$ if you change the initial values to something like $y(0) = 2$, $y'(0) = 0$. The solution does have $y$ an invertible function of $x$ but this is not known a priori. If you just blindly work through the integration without worrying you still get the solution $y(x) = e^x + e^{-x}$, no matter which branch of the square root $\pm \sqrt{y^2 - 4}$ you pick (and in fact $y'$ changes sign near $x = 0$, so neither of these is valid even locally).
Is there a way to make this work rigorously? Or are there similar equations and initial values where this substitution misses a solution? I'm not so worried about it introducing extraneous solution although I do not have an example of that either.
I originally learnt this solution in high school from a physics-y book that did not justify the differentiability, as is usual in high school level physics-y books. Actually in that book the original solution was for the simple harmonic motion equation $y'' = -\omega^2 y$ but, as I noticed later, the same substitution seems to help with some other second order ODEs too.
Your manipulation ultimately ends up being the ODE $yy' = y' y''$ in disguise which is of trivially statisfied by any solution to the original ODE. Separating variables on the equivalent (for nonzero $y$) $y' = \frac{y' y''}{y}$ then results in solving $y' = (y' y'') \frac{1}{y}$ where $y'y''$ is the term you'd integrate over $x$ and $\frac{1}{y}$ the one to integrate over $y$. So using the "less problematic" version of separation of variables you just integrate $y y' = y' y''$ over $x$: $$ \textbf{LHS:} \quad \int y y' dx = \int y dy = \frac{y^2}{2} \\ \textbf{RHS:} \quad \int y' y'' dx = \int y' dy' = \frac{y'^2}{2} + C. $$ Together we thus get the new ODE $y^2 = y'^2 + C$ which we can easily solve (you can find that $C=8$ by plugging in the initial conditions).
So basically you can avoid the whole substitution by first working things through with it, and then just eliminating it in a way that avoids all potentially undefined or problematic quantities.