Immediately, I can recognize some components of the mean value theorem. $\frac{1}{n^2}$ likely comes from the slope of $f$ at $n$, and the $|\frac{1}{n} - \frac{1}{x}|$ expression likely comes from the secant expression $\frac{\frac{1}{n} - \frac{1}{x}}{x}$. But I cannot figure out how they fit together in the end.

If $x = n$, then the left hand side is $0$ and the result holds. So let's assume that $n < x \leq n+1$. Then applying the mean-value theorem to the function $f(t) \colon= 1/t$ for $t \in [n, x]$, we find that there is a real number $c \in (n,x)$ such that
$$ f(x)-f(n) = f\prime(c) \cdot (x-n) $$
or
$$\frac{1}{x}-\frac{1}{n} = - \frac{1}{c^2} \cdot (x-n). $$
So
$$ |\frac{1}{n}-\frac{1}{x}| = \frac{1}{n}-\frac{1}{x} = \frac{1}{c^2} \cdot (x-n) \leq \frac{1}{c^2} < \frac{1}{n^2}. $$
We of course assume that $n$ is positive.

Assume $n>0$.
By mean value theorem, there exists $c\in(n,n+1)$ such that
$$\frac{1}{n}-\frac{1}{x}=\frac{1}{c^2}(x-n)$$
Since $c>n$, we get $c^2>n^2$. So
$$\left|\frac{1}{n}-\frac{1}{x}\right|<\frac{x-n}{n^2}\le\frac{1}{n^2}.$$