I have a question from Algebraic geometry by Robin Hartshorne. My question is regarding a proof in this book. The proof is the following:

Lemma. Let $\displaystyle X$ be a variety and $\displaystyle Y \subseteq \mathbb{A}^n$ be an affine variety. Let $\displaystyle x_1, \ldots, x_n$ be the coordinate functions on $\displaystyle \mathbb{A}^n$. A map of sets $\displaystyle \psi : X \rightarrow Y$ is a morphism if and only if $\displaystyle x_i \circ \psi$ is a regular function on $\displaystyle X$ for each $\displaystyle i=1, \ldots, n$.

Theorem. Let $\displaystyle X$ be a variety and $\displaystyle Y$ be an affine variety. Then there is a natural bijective mapping of sets
$\displaystyle \alpha : \text{Hom}(X, Y) \overset{\sim}{\rightarrow} \text{Hom}(A(Y), \mathcal{O}(X))$. Here the leftside indicates morphisms of varieties and the rightside indicates homomorphisms of $\displaystyle k$-algebras.

Proof. Let $\displaystyle \phi: X \rightarrow Y$ be a morphism. Then $\displaystyle \phi$ takes regular functions on $\displaystyle Y$ to regular functions on $\displaystyle X$. So $\displaystyle \phi$ induces a map $\displaystyle \mathcal{O}(Y)$ to $\displaystyle \mathcal{O}(X)$ . This is clearly a homomorphism of $\displaystyle k$-algebras. However, by a result in Hartshorne, $\displaystyle \mathcal{O}(Y) \cong A(Y)$. So we get a homomorphism $\displaystyle A(Y) \rightarrow \mathcal{O}(X)$. This defines $\displaystyle \alpha$.

Conversely, let $\displaystyle h : A(Y) \rightarrow \mathcal{O}(X)$ be a homomorphism of $\displaystyle k$-algebras. Suppose $\displaystyle Y$ is a closed subset of $\displaystyle \mathbb{A}^n$ such that $\displaystyle A(Y)=\frac{k[x_1, \ldots, x_n]}{I(Y)} $. Let $\displaystyle \overline{x_i}$ be the image of $\displaystyle x_i$ in $\displaystyle A(Y)$. Now consider the elements $\displaystyle \sigma_i=h(\overline{x_i}) \in \mathcal{O}(X)$. The $\displaystyle \sigma_i$ are global functions on $\displaystyle X$. So we can define a map $\displaystyle \psi : X \rightarrow \mathbb{A}^n $ by $\displaystyle \psi(P)=(\sigma_1(P), \ldots, \sigma_n(P))$ where $\displaystyle P \in X$.

Now we need to show that the image of $\displaystyle \psi$ is contained in $\displaystyle Y$ . Because $\displaystyle Y=V(I(Y))$ , it suffices to show that for any $\displaystyle P \in X$ and any $\displaystyle f \in I(Y) $, $\displaystyle f(\psi(P))=0 $. However, $\displaystyle f(\psi(P))=f(\sigma_1(P), \ldots, \sigma_n(P))$. Note that $\displaystyle f$ is a polynomial and $\displaystyle h$ is a homomorphism of $\displaystyle k$-algebras, so we have $\displaystyle f(\sigma_1(P), \ldots, \sigma_n(P))=h(f(\overline{x_1}, \ldots , \overline{x_n} ))(P)=0$ because $\displaystyle f \in I(Y)$. So $\displaystyle \psi$ defines a map from $\displaystyle X$ to $\displaystyle Y$ that induces the homomorphism $\displaystyle h$. It now remains to show that $\displaystyle \psi$ is a morphism. This is a consequence of the lemma.

I don't understand this part of the proof:

It now remains to show that $\displaystyle \psi$ is a morphism. This is a consequence of the lemma.

Why is $\displaystyle \psi$ a morphism? How is this a consequence of the lemma? I can't figure this out. Thank you.