Rigorous separation of variables.
Solution 1:
I have written a long Section of a Chapter on this, in my ODEs book, but it is in Greek. If you understand I can send it to you. The spirit is the following: How to make separation of variables rigorous.
However, I wish to make a comment. There are solutions which do not belong in your sets when uniqueness is violated. For example: Let the equation $$ y'=\lvert y\rvert^{1/2}. $$ Then one solution of the above is $$ \varphi(x)=\left\{\begin{array}{lll}0 & \text{if} & x\le 0, \\ x^2/4 & \text{if} & x>0.\end{array}\right. $$ Note that that $g(\varphi(x))$ vanishes for $x\le 0$, and is positive for $x>0$.