Is the following integral expression correct (neglecting the constant of integration)?
$$ \int\cos\left(\frac{1}{x}\right)dx = x^2\sin\left(2x\right) $$
When I take the derivative, it returns to the integral, so it's ok, right? For some reason I can't find this integral over the internet, and Wolfram gives a strange answer.
Let us check by differentiating your claimed antiderivative.
Call $F(x) = x^2 \sin(2x)$. Then $F'(x) = 2x\sin(2x) + 2x^2\cos(2x)$. Now we ask, is $F'(x)$ the same as $\cos(1/x)$?
Although there are many ways to understand it, they are not the same. For instance, $\cos(1/x)$ is bounded by $1$ always, while $F'(\pi)$ is much larger.
So they are not the same. In fact, $\displaystyle \int \cos(1/x) dx$ has no elementary antiderivative.