I'm trying to give a motivational explanation for why morphisms between algebraic sets $X \subset \mathbb{A}^n$ and $Y \subseteq \mathbb{A}^m$ is defined the way that it is defined, that is, that it is the set of polynomial maps $\mathbb{A}^n \rightarrow \mathbb{A}^m$ restricted to the domain $X$ and codomain $Y$. Many texts simply say that it is natural to define morphisms between varieties to be polynomial maps between algebraic sets, because algebraic sets are zero loci of polynomials, but I just cannot seem to get to the point where I feel myself "getting it", so to speak. Therefore, I have been trying to come up with a motivational explanation of my own. But here to, I run into problems.
Now, let's say that $X \subset \mathbb{A}^n$ and $Y \subseteq \mathbb{A}^m$ are algebraic sets. Then that means that $X$ and $Y$ are the zero loci of some set of polynomials $f_i \in K[x_1, \dots, x_n]$ (call it $T$) and $g_i \in K[y_1 , \dots , y_m]$ (call it $S$). Let's say then that we have a map $\varphi : \mathbb{A}^n \rightarrow \mathbb{A}^m$, and let's ask what conditions we need to put on it to make it a morphism $X \rightarrow Y$.
$\varphi$ then induces a map from the set of functions $\mathbb{A}^m \rightarrow K$ (denote it $\mathcal{F}[\mathbb{A}^m]$) to the set of functions $\mathbb{A}^n \rightarrow K$ (denote it $\mathcal{F}[\mathbb{A}^n]$), $\varphi^{*} : \mathcal{F}[\mathbb{A}^n] \rightarrow \mathcal{F}[\mathbb{A}^m]$, by $g(y_1 , \dots , y_m) \mapsto f(z_1 , \dots , z_n) = g (y_1 (z_1 , \dots , z_n), \dots , y_m (z_1 , \dots , z_n))$.
We want our morphism to be such that points in $X$ are mapped to points in $Y$. Since $Y = \{ (y_1 , \dots , y_m) \in \mathbb{A}^m | g_i (y_1 , \dots , y_m) = 0 , \forall g_i \in S \}$, this then means that we will have $g_i (\varphi(x_1 , \dots , x_n)) = 0$ for all $(x_1 , \dots , x_n) \in X$, and so $X$ may be described as $X = \{ (x_1 , \dots , x_n) \in \mathbb{A}^n | g_i (\varphi (x_1 , \dots , x_n)) = 0 , \forall g_i \in S \}$.
Now this is the point at which I am struggling.
It is known that the zero locus of general functions $h_i : \mathbb{A}^n \rightarrow K$ is not necessarily an algebraic set. For example, the set $\{ (x,y) | y - \sin^2(x) = 0 \}$ can be shown not to be algebraic. If I could show that we need to have $\varphi$ be a polynomial map for the $\{ (x_1 , \dots , x_n) \in \mathbb{A}^n | g_i (\varphi (x_1 , \dots , x_n)) = 0 , \forall g_i \in S \}$ to actually define an algebraic set, I would basically have the whole definition justified.
The problem is, though, I don't really know how to go about doing that. Is that even possible? Can I find non-polynomial $\varphi: X \rightarrow Y$ such that $\{ (x_1 , \dots , x_n) \in \mathbb{A}^n | g_i (\varphi (x_1 , \dots , x_n)) = 0 , \forall g_i \in S \}$ still defines an algebraic set in $\mathbb{A}^n$? Do I need to add further requirements?
As always, any and all help will be greatly appreciated!