Zariski topology finer than product topology
What's going on here is greatly clarified if you think of the two coordinate spaces of the product as being separate, totally unrelated spaces. So instead of thinking of $U$ and $V$ as both being subsets of the same polynomial ring $k[x]$, they are now subsets of two separate polynomial rings: $U\subseteq k[x_1]$ and $V\subseteq k[y_1]$. Now it's easy to guess what $Y$ should be: just take the union of $U$ and $V$ inside $k[x_1,y_1]$.
In terms of your original notation, this means $$Y=\{f(x_1):f(x)\in U\}\cup\{g(y_1):g(x)\in V\}.$$ I'll leave it to you to verify that this $Y$ works.
The Zariski closed subsets in $A^1$ are the finite subsets and $A^1$.
If all the subsets $X_i$ and $Y_i$ are finite, you can suppose without really restricting the generality that $X_i=\{x_i\}, Y_i=\{y_i\}$, $\bigcup_i X_i\times Y_i=Z(I)$ where $I$ is the ideal generated by $(X-x_i,Y-y_i)$.
If one $X_i$ and one $Y_j$ is $A^1$, then $A\times A=\bigcup_i X_i\times X_j$.
If you have some $X_i=A^1$ and no $Y_i$ is $A^1$, then $\bigcup_iX_i\times Y_i$ is the union of a finite subset $F$ and lines defined $Y=y_i$ if $X_i=A^1$. You conclude by saying that a finite union of Zariski closed subsets is closed.