Consider this homogeneous differential equation:
$$xy'=y+2\sqrt{xy}$$
We divide the equation by $x$ and write it as $$y'=\frac yx+2\sqrt{\frac yx}$$ Then substitute $v=\frac yx$ and so on.
But how this is valid? I mean first of all we can divide by $x$ if $x\ne0$ and more importantly by dividing second term of RHS by $x$ in fact we did:
$$\frac{\sqrt{xy}}{x}=\frac{\sqrt{xy}}{\sqrt{x^2}}=\sqrt{\frac{xy}{x^2}}=\sqrt{\frac yx}$$
But $x=\sqrt {x^2}$ is true when $x\ge0$ for negative values of $x$ it doesn't work. So my question is how dividing the equation by $x$ is valid?
You are correct, this is a concern.
However, the equation is singular, the domain is split by the line $x=0$, and restricted by $xy\ge 0$, so that one has to compute solutions in the parts $x<0$ and $x>0$ separately. The solution that you discuss seems to automatically assume that $x>0$, $y\ge 0$.