$$\frac{1}{y} \frac{\text{d}y}{\text{d}x} = \frac{1}{x}$$

The way I solve this:

for all $x$ in $(-\infty,0)$

$\ln |y| = \ln |x| + A$ where $A$ is a real constant (since we know antiderivatives are separated by a constant)

$|y| = B|x|$ where $B$ is a positive constant equals $\exp(A)$

$y= Bx$ or $-Bx$

It seems to me $y =Cx$ where $C$ is a real non-zero constant that equals either $B$ or $-B$.

Since it seems like if $y$ is equal to $+$ or $-Bx$ for the entire interval $(-\infty,0)$, then it must be only $+Bx$ or $-Bx$ i.e. $Cx$ for some subinterval. If it is $+Bx$, then for values outside and near this interval, they must also be $+Bx$ since we know $y$ is continuous and $x$ is not zero. Vice versa.

But I don't know how to prove this. How to prove $y = Cx$ for $(-\infty, 0)$?

If that is the case, then I can write the general form of the differential equation picewisely as $y=C\_1x$ for $(-\infty,0)$, $C\_2x$ for $(0,\infty)$, where $C\_1$ and $C\_2$ are non-zero reals.
['https://math.stackexchange.com/questions/4343424', 'https://math.stackexchange.com', 'https://math.stackexchange.com/users/840119/']
The first point of confusion here is that you antidifferentiatied $$\frac{y'}{y}=\frac1{x}$$ to $$\ln(|y|)=\ln(|x|)+A,$$ but this is not entirely correct. The antiderivatives of $\frac1{t}$ are given by the piecewise, $$\ln(-t)+A;\,\forall{t\lt0}$$ $$\ln(t)+A;\,\forall{t\gt0}.$$ Taking this into account, you should have $$\ln(-y)=\ln(-x)+A$$ or $$\ln(y)=\ln(-x)+B.$$ This translates to $$y(x)=\exp(A)x$$ or $$y(x)=-\exp(B)x.$$

The second point of is in interpreting the "or." The two solutions we have here are that $y(x)=c\_0x$ with $c\_0\gt0,$ or that $y(x)=c\_1x$ with $c\_1\lt0.$ You could not have both happening simultaneously in all of $(-\infty,0).$ Your question is, how do you prove it? Well, notice that the equation must be satisfied everywhere. But it cannot be satisfied if there are jump discontinities, which occur if you have a constant of one kind in one subinterval, and a constant of some other kind everywhere else. You can show that if $$f(x)=\begin{cases}Ax&x\leq{C}\\Bx&x\gt{C}\end{cases},$$ then $f$ is not even differentiable at $C$ unless $A=B.$ You can prove it just using the definition of the derivative. The method for solving the equation, when done properly, already implies this, though, so in practice, you would not need to prove it.
Consider the DE in its explicit normal form $\frac{dy}{dx}=\frac{y}{x}$. The difference is that the equation is now defined for $y=0$, inside the quadrants the solutions remain the same.

As an ODE, this equation is singular or not defined on the line $x=0$. Thus the solutions on $(-\infty,0)$ and $(0,+\infty)$ are separate, with separate integration constants. For the solution as ODE one need not care much of how they connect at $x=0$.

$y=0$ is a solution of the explicit ODE, or outside the domain for the original equation. Thus no other solution can change its sign, trivially by not being able to leave its quadrant, or by the uniqueness property of the Picard-Lindelöf (-Cauchy-Lipschitz) theorem on existence and uniqueness. As the sign is fixed, it is determined by the initial condition, one could write
$$
\frac{x}{x\_0}=\frac{y}{y\_0}.
$$