Here's how you prove that it's correct, if you've just plucked out of the air that the answer is $\tan^{-1}$ and you want to know why this is.
$$\int \frac{1}{1+x^2} \ \mathrm{d}x$$
Consider $\dfrac{\mathrm{d}}{\mathrm{d}x} \tan^{-1} \tan(x) = \sec^2(x) {\tan^{-1}}'(\tan(x))$ by the chain rule.
The left-hand side is just the derivative of $x$, so is $1$.
So multiplying both sides by $\cos(x)^2$, have $\cos(x)^2 = {\tan^{-1}}'(\tan(x))$.
So (writing $x = \tan^{-1}(u)$) have ${\tan^{-1}}'(u) = \cos(\tan^{-1}(u))^2$.
Now consider $\cos(x)^2 + \sin(x)^2 = 1$, so $1 + \tan(x)^2 = \sec(x)^2$; letting $x = \tan^{-1}(u)$, obtain $$1 + \tan(\tan^{-1}(u))^2 = \sec(\tan^{-1}(u))^2$$
where the left-hand side is just $1+u^2$, so $\cos(\tan^{-1}(u))^2 = \frac{1}{1+u^2}$.
Therefore ${\tan^{-1}}'(u) = \frac{1}{1+u^2}$, and hence integrating both sides $$\tan^{-1}(u) = \int \frac{1}{1+u^2} \ \mathrm{d}u$$