Let $i: Z\rightarrow X$ be the inclusion of $Z $ as a subspace of $X $. Let $\mathscr{F}$ be a sheaf on $X$. The restriction of $\mathscr{F}$ to $ Z $ is defined as the sheafification of $U\mapsto \varinjlim_{V\supset f(U)}\mathscr{F}(V)$. Hartshorne's book says the stalks of this restriction are the same as those of $\mathscr{F}$. I can't figure out why. This is obvious if $ Z $ is open, since the neighborhoods of a point in $ Z $ form a cofinal set. Why is it true in general?
I tried to form an adjunction of some sort to show that the restriction commutes with colimits, but I couldn't.
The sheafification has the same stalks as the presheaf you describe, so it will be enough to show that
$$\varinjlim_{U:~x\in U}~\varinjlim_{V:~i(U)\subset V}\mathscr{F}(V)=\varinjlim_{V:~i(x)\in V}\mathscr{F}(V).$$
But this is really the same direct limit. Indeed, if $V$ contains $i(U)$ for some $U$ containing $x$, then it must contain $i(x)$. Conversely, if $V$ is open and contains $i(x)$, then $U=i^{-1}(V)$ is an open subset containing $x$ and contained in $V$.
You should be able to use this to prove that the left hand side has the universal property for the direct limit on the right hand side (and vice versa).