I expect you asked the physicists rather than the mathematicians. The mathematicians might roll their eyes a little at those awful sloppy physicists, but would also be able to explain why it works (in so far as it does) and say a bit about the sort of worries that make mathematicians uneasy about such notational carelessness.

Here's what I'd say if asked.

The handwavy idea is that derivatives are limits of difference ratios, and integrals are limits of sums, and if you let dx,dy stand for the finite changes whose ratios and sums we are working with it makes perfectly good sense to go from dx/dy = f(x) to dy = f(x) dx, and it turns out that when you do all the adding up and taking limits everything still works -- provided all the functions involved are "nice enough", which in physics they almost always are, but the possibility that they might not be is why mathematicians get cross about this sort of sloppiness.

Let's fill in the details.

"dy/dx = f(x)" means: there is some currently-unknown functional dependence of y on x; when you make very tiny changes in x and y consistent with this functional dependence, the ratio of those very tiny changes is always approximately f(x), in the sense that you can force the ratio to be as near f(x) as you like by requiring the changes to be small enough.

Well, if for small changes dy/dx is as close as you like to f(x) then dy is as close as you like to f(x) dx, in a slightly stronger sense: the error divided by dx is as small as you like, even though dx is very small.

Now, let's think about those integrals. When we write "integral dy" or "integral f(x) dx" this is shorthand for the thing you get very close to by adding up lots of things that look like "dy" or "f(x) dx", with the value of x or y advancing in tiny steps from an initial to a final value. (I am talking specifically about definite integrals here, but we can be lazy and not always write down the endpoints.)

In the situation we're looking at, we know that "dy" and "f(x) dx" are always very close to one another: they differ by as small a multiple of f(x) as you please. So when we look at the sums that are approximations to those integrals, the difference between them is as small a multiple of the total change in x as you please. So if we fix the endpoints of the integrals, this means that the sums can be made as close together as you like; so the integrals, being the limits of those sums, must be equal.

But! There's one thing there about which you should be a little uneasy. For each specific (x,y) we can make dy/dx as close as you like to f(x) by requiring dx to be very small. But what if this doesn't happen "uniformly"? I.e., what if the dependence of y on x is "less differentiable" at some points than at others? Then we'd have to make the steps smaller in some places than in others, maybe by an unbounded factor, and maybe that causes trouble. And you'd be right to worry about this. There are in fact possible ways the dependence of y on x could go that fail in just this sort of way. (See e.g. https://en.wikipedia.org/wiki/Volterra%27s_function.) But they require y to be a rather pathological sort of function of x, and if e.g. your function f is continuous then the trouble can't arise.