Is this solution mathematically "legal"?
This is not valid. To distribute limits, the individual limits must exist. As Matthew notes, the limit of $\cos n$ does not exist so you cannot distribute them in this way. However what you do know is that
$$\left|\frac{n\cos n}{n^2+1}\right| \le \frac{n}{n^2+1}$$
since $\cos$ is bounded by $\pm 1$. From here apply the squeeze theorem.
More simply, you can do that with asymptotic analysis and equivalents:
- $\cos n=O(1)$,
- $\dfrac n{n^2+1}\sim_\infty\dfrac1n$,
hence: $$\frac{n\cos n}{n^2+1}=O\Bigl(\frac1n\Bigr)\xrightarrow[n\to\infty]{}0.$$
Your method has one minor technical error. In your method you are computing $\lim_{n \to \infty}{\cos(x)}$, which does not exist. The key to taking this limit is noting that $\cos(x)$ is bounded. That is,
\begin{align} -1 \leq \cos(n) \leq 1 \end{align}
Hence,
\begin{align} -\frac{n}{n^2+1} &\leq \frac{n\cos(n)}{n^2+1} \\ &\leq \frac{n}{n^2+1}. \end{align}
Note that
\begin{align} \lim_{n \to \infty}-\frac{n}{n^2+1} &= \lim_{n \to \infty}\frac{n}{n^2+1} \\ &= 0, \end{align}
by L'Hopitals rule, for example. Hence, by the squeeze theorem,
\begin{align} \lim_{n \to \infty}\frac{n\cos(n)}{n^2+1} &= 0. \end{align}