I'm considering this limit: $$\lim\limits_{x \to 0} \frac{x \cos(x) - \sin(x)}{x \sin^2(x)}$$
If I apply de l'Hôpital's rule I get $-\frac{1}{3}$, while if I immediately simplify the $x$ like this:
$$\frac{\cos(x) - \frac{\sin(x)}{x}}{\sin^2(x)}$$
I get $-\frac{1}{2}$ as result, because I write it as (remembering that $\frac{sin(x)}{x} = 1$):
$$\frac{cos(x) - 1}{x^2}$$
which I simplify it with $-\frac{1}{2}$.
What am I getting wrong?
tl;dr: Your error is in the second step. You substitute $\frac{\sin x}{x}$ by its limit, $1$. But this is getting rid of the low-order terms, which matter.
One way to see it rigorously is to do a polynomial approximation near $0$, that is a Taylor expansion: when $x\to 0$, $$ \frac{\sin x}{x} = 1-\frac{x^2}{6} + o(x^2) $$ so that you neglect a term "behaving like" $\frac{x^2}{6}$. Does it matter? Well, again, near $0$: we have $$ \cos x = 1-\frac{x^2}{2} +o(x^2) \tag{1} $$ so $$\begin{align} \cos x - 1 &= -\frac{x^2}{2} +o(x^2) \tag{2}\\ \cos x - \frac{\sin x}{x} &= 1-\frac{x^2}{2} +o(x^2) - \left(1-\frac{x^2}{6} + o(x^2)\right) = -\frac{x^2}{3} +o(x^2) \tag{3} \end{align}$$ which explains the difference you get between you two methods. The low-order term you (erroneously) dismissed in the second did have a role to play.