Both are ok if you have constant coefficient linear homogeneous ODE's, as in your example, but there are some subtleties in other cases.
The difference between the two variants is that in the first case you're writing down an identity between numbers (left and right of the equal sign there are numbers), while in the second case you're writing down an identity between functions (i.e., maps from a subset $U\subset \mathbb{R}$ to $\mathbb{R}$).
You made it quite clear that you want $y$ to be function $U \to \mathbb{R}$ in the modern sense of the word. I emphasize this because there's also the historical way to understand the word "function" and to write the ODE, which I'll mention at the end. But for everyone to be on the same page: in your setting $y(x)\in \mathbb{R}$ while $y\in \operatorname{Maps}(\mathbb{R},\mathbb{R})$, and numbers and maps are different types of mathematical objects. There's no natural way to identify a number with a map, meaning there's no natural isomorphism between $\mathbb{R}$ and $\operatorname{Maps}(\mathbb{R},\mathbb{R})$.
A small problem with your first way of writing the equation is that you should have added a quantifier $\forall x \in U$. If you don't do this, that equation contains two free variables $y$ and $x$, and could/should be read as a condition on the pair $(x,y)$, where $x$ is a number and $y$ a map. One solution of that equation would, for instance, be the pair $x=-4/3$ and $y=(x\mapsto x)$ and many others, which is not what you want. But in practice, no one ever writes $\forall x$ next to the ODE, just like no one writes $\forall x$ next to the definition of a function $f$ when they declare $f(x)=x^2$. This habit has historical reasons that are related to the third option I'll mention at the end. I do suspect though that leaving out the $\forall x$ can confuse some students if you emphasize the modern notion of function a lot in your teaching.
Having said that, consider an ODE like in Amit's answer or the linear ODE
$$y'(x)+3xy(x)=x^2\quad \forall x\in U$$
How to write it in your proposed second way? Just leaving out the $(x)$ would be problematic since the resulting equation $$y'+3xy=x^2$$should be an equation between maps but contains numbers $x$ and $x^2$ on both sides. The most common (and consistent) way to interpret numbers in an equation between maps is to see them as constant maps (given a $c\in \mathbb{R}$ interpret it as the map $f(x)=c$). But then the solution of that equation would be: $y=(u\mapsto \frac{x}{3} + C\exp(-3xu))$, which is again not what you want. Some people might object to what I'm doing here, saying "it's obvious that $x^2$ should not be interpreted as a constant function but as $x\mapsto x^2$". But suppose you see an ODE like $r'+3\sin(a)r=c^2$. It's natural to assume that $r$ is a function $r\in \operatorname{Maps}(\mathbb{R},\mathbb{R})$. But how are we to interpret $a$ and $c$? As constants? Or should we maybe interpret $\sin(a)$ as the function $\sin$ and $c$ as a constant, or the other way round, $c^2$ as the map $c\mapsto c^2$ and $\sin a$ as constant? (We clearly cannot interpret both as functions). We would get different ODEs depending on the interpretation. Someone might object that if we don't use the letters $y$ and $x$ we just have to be more explicit. I dislike such ad hoc rules and believe that the person really wants to use the original notion of function.
In any case, if you want to take the modern notion of function seriously, the correct way to write the ODE $y'(x)+3xy(x)=x^2 \forall x \in U$ as an identity between maps is to either write
$$y'+3(x\mapsto x)y=(x\mapsto x^2)$$
or else to make up names for the functions $x\mapsto x$ and $x\mapsto x^2$, say $g(x)=x$ and $h(x)=x^2$, and then write $$y'+3gy=h.$$Both options look strange and would probably make calculations (separation of variables, variation of constants, etc.) very awkward. I've never seen someone do this.
So assuming you want to take the modern notion of function seriously (and not come up with ad hoc rules of what certain letters mean in which context), it seems like you're stuck with your first option of writing $y'(x)+3xy(x)=x^2 \forall x \in U$.
From your comments below the question I see that you feel fine writing things like $y=y(x)$, and looking at your homepage, I see that you have a partial background in physics. This makes me believe that what you really want is to use the word "function" in its original sense. I've written about this in different places on Stackexchange, a starting point could be here
To make it short, if you don't interpret $y$ as a modern function but as a "function of $x$", hence as a number depending on the number $x$ (which might sound less strange if you read it as "a quantity depending on another quantity", so $y\in \mathbb{R}$ and not $y\in\operatorname{Maps}(\mathbb{R},\mathbb{R})$), then you can and should write
$$\frac{dy}{dx}+3xy=x^2$$
without any quantifier. The problem with the other equation also disappears if we write, say
$$\frac{dr}{da}+3\sin(a)r=c^2.$$