Why is it legitimate to solve the differential equation $\frac{dy}{dx}=\frac{y}{x}$ by taking $\int \frac{1}{y}\ dy=\int \frac{1}{x}\ dx$?
To be honest I think it's BS to teach separable variables like this without the Riemann-Stieljes integral.
The way I solve them is by doing what actually is done: integrate with respect to $x$ on both sides.
Remember that $y$ is a function (on the variable $x$). So your differential equation is, for all $x$ in a certain interval, $y'(x)=\dfrac{y(x)}{x}$ or equivalently $\dfrac{y'(x)}{y(x)}=\dfrac {1}{x}$and integrating with respect to $x$ you get the desired result.
In my opinion integrating with respect to $y$ is nothing more than a cheap trick, the same way $\dfrac{dy}{dx}=1\iff dy=dx$ is a cheap trick. It works only because of some higher math.
More generally, if you can rewrite your DE as $g(y(x))y'(x)=f(x)$ for some functions $f$ and $g$ that have antiderivatives, $F$ and $G$, in the given interval, then $g(y(x))y'(x)=f(x)\iff G(y(x))=F(x)+C$, for some $C\in \Bbb R$. (To establish $\Longleftarrow$ just differentiate). And if we're lucky enough for $G$ to be invertible, we get $y(x)=G^{-1}\left(F(x)+C\right)$. If $G$ isn't invertible, then hopefully the implicit function theorem will yield the solutions to the DE implicitly by the equation $G(y(x))=F(x)+C$.
In your example $g$ is the function $t\mapsto \dfrac{1}{t}$ which has $t\to \log (|t|)$ as an antiderivative. (Don't forget the absolute value).
You start with $$ y'=\frac{y}{x}\implies \frac{y'}{y}=\frac{1}{x}\implies\int\frac{y'dx}{y}=\int \frac{dx}{x}, $$ and you make the change of variables in the first integral, which results in what you've written $$ \int\frac{dy}{y}=\int \frac{dx}{x} $$
I don't like the notation that's often used when solving ODEs. I'd prefer to write the solution like this:
\begin{align} & y'(x) = \frac{y(x)}{x} \quad \text{for all }x > 0 \\ \implies & \frac{y'(x)}{y(x)} = \frac{1}{x} \quad \text{for all }x > 0 \\ \implies & \log y(x) = \log x + C \quad \text{for all } x > 0 \,(\text{for some } C \in \mathbb R). \end{align}
(I'm assuming $y(x) > 0$ for all $x>0$.)