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

Theorem. Let X be a variety and Y be an affine variety. Then there is a natural bijective mapping of sets
\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 k-algebras.

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

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

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

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