When can you divide out $dx$ in an integral as if it is a fraction?

It is a common misconception that $dx$ is an "infinitesimal". $dx$ is a differential, i.e. an arbitrary, nonzero quantity representing a variation.

When there is a dependent variable, say $y=f(x)$, the differential of $y$ is related to that of $x$ by

$$dy=f'(x)\,dx.$$

By this definition, $dy$ is "the linear part of the variation of $y$ for a given variation of $x$", as explained by Taylors' development.

This is to be contrasted with

$$\Delta y=f(x+\Delta x)-f(x)=f'(x)\Delta x+R(x,\Delta x)$$ (where $R$ is a remainder term) which is the ordinary variation.

Hence, $dx,dy$ can really be handled like numbers, and

$$\frac{dy}{dx}=f'(x)=\lim_{\Delta x\to 0}\frac{\Delta y}{\Delta x}.$$


Example:

For the function $y=x^2$,

$$\Delta y=(x+\Delta x)^2-x^2=2x\Delta x+\Delta^2 x$$ while the linear part is

$$dy=2x\,dx.$$


Note that $dx$ and $\Delta x$ both represent arbitrary variations, but I kept both for the symmetry of the formulas.