This is due to the continuity of $\cos(x)$. Generally a function $f$ is continuous if
$$
\lim_{x \to a} f(x) = f(a)
$$
which in qualitative terms says if I move $x$ closer and closer to $a$ then $f(x)$ will get closer and closer to $f(a)$ (this getting closer and closer occurs at about the same rate).
Now in some simplistic terms we can consider a sequence $\{a_n\}$ to converge to a point $\pi$ to mean that as $n$ increases unboundedly, the terms of the sequence get closer and closer to $\pi$.
Intuitively, then, we can make the jump that since $a_n$ gets closer and closer to $\pi$ we can say that
$$
\lim_{n \to \infty} f(a_n) = f\left( \lim_{n \to \infty} a_n \right)
$$
Of course this can all be proven rigorously (which I'll gladly show you how if you want) but I hope this provides some intuition.
Also note that $\cos \pi = -1$ not $0$ ;D