After many edits, here is my question:
Is it true for a scheme $S$ that $\mathcal O(S\times \mathbb A_\mathbb Z^n) = \mathcal O(S)\otimes_\mathbb Z \mathcal O(\mathbb A^n)$ or not?
Let $\mathbb A$ be the forgetful functor on the category of commutative rings. It is a ring object internal to the category of functors on $\text{cRing}$. For each functor $X:\text{cRing}\to \text{Set}$, let $\mathcal O(X) = \text{Hom}(X,\mathbb A)$ be the set of natural transformations form $X$ to $\mathbb A$. Each $\mathcal O(X)$ get a ring structure from the internal ring structure of $\mathbb A$.
Is it true that $$\mathcal O(S\times \mathbb A^n) = \mathcal O(S)\otimes_\mathbb Z \mathbb Z[x_1,...,x_n] = \mathcal O(S)[x_1,...,x_n]$$ as commutative rings?
I read lecture notes from Marc Nieper-Wißkirchen which claim this, but I am not able to compute it myself. I feel really stupid. There is an adjunction $\text{Hom}_{\text{Pr}(\text{cRing}^{op})}(X,yA) = \text{Hom}_{\text{cRing}}(A,\mathcal OX)$, but it only implies that $\mathcal O$ sends colimits to limits. I know that the equation is true for representable $S$. Do I need to write the functor $S$ as a colimit of representables?
Edit. It seems like the result is not true for a general functor. We can pass to the smaller subcategories of sheaves in the Zariski topology and of (functorial) schemes. Colimits in the big Zariski topos Zar of sheaves in the Grothendieck topology are computed differently than in the presheaf category (sheafification). The ring $\mathcal O(S\times \mathbb A^n)$ does not depend on the surrounding category though. Does the equation $\mathcal O(S\times \mathbb A^n) = \mathcal O(S)[x_1,...,x_n]$ at least hold if $S$ is a scheme?
Edit. Edit. Okay, now I am totally confused. Qiaochu Yuan claims below that $\mathcal O(S\times \mathbb A^n) \neq \mathcal O(S)[x_1,...,x_n]$ for general schemes, but I have the following argument.
According to the stacks project the projection map $\mathbb A^n\times S\to S$ is up to isomorphism $\underline{Spec}_S(\mathcal O_S[T_1,...,T_n])\to S$. The Spec thing here is the relative spec construction and it acts on a $\mathcal O_S$-algebra! Let me denote the structure map by $$p:\underline{Spec}_S(\mathcal O_S[T_1,...,T_n])\to S$$ Now the relative Spec construction satisfies in general that $p_*\mathcal O_{\underline{Spec}_S\mathcal A} = \mathcal A$ for any $\mathcal O_S$-algebra $\mathcal A$. So I can compute the global functions on the scheme over $S$ as follows. \begin{align}\mathcal O(S\times \mathbb A^n) &= \mathcal O(\underline{Spec}_S(\mathcal O_S[T_1,...,T_n])) \\&= \mathcal O_{\underline{Spec}_S(\mathcal O_S[T_1,...,T_n])}(p^{-1}S)\\ &= p_*\underline{Spec}_S(\mathcal O_S[T_1,...,T_n])(S) \\&= \mathcal O_S[T_1,...,T_n](S)\\ &= \mathcal O(S)[x_1,...,x_n] \end{align} Here $\mathcal O_S$ is a sheaf of algebras and $\mathcal O(S)$ is a ring! What is wrong with my calculation? The step where I am not sure about is what the global sections of the sheaf $\mathcal O_S[T_1,...,T_n]$ are. Is the counterexample incorrect? (I must admit that I do not understand it completely).
The original lecture notes can be found at the end of the article as a pdf, and the claim by M. Nieper-Wißkirchen is on page 58 equation (4.5.12)
Also here is an argument which I believe does work for schemes which can be covered by finitely many open affines. Write $S$ as a colimit $S = \text{colim}_iU_i$ of finitely many open affine subfunctors. Make the following computation \begin{align} \mathcal O(\mathbb A^n\times S) &= \mathcal O(\mathbb A^n \times (\operatorname{colim}_{i}U_i))\\ &= \mathcal O(\operatorname{colim}_i(\mathbb A^n\times U_i)) \\ &= \operatorname{lim}_i\mathcal O(\mathbb A^n\times U_i) \\ &= \operatorname{lim}_i(\mathcal O\mathbb A^n \otimes_\mathbb Z \mathcal OU_i) \\ &= \mathcal O\mathbb A^n \otimes_\mathbb Z \operatorname{lim}_i\mathcal OU_i \\ &= \mathcal O\mathbb A^n\otimes_\mathbb Z\mathcal OS \end{align} where I now used that $-\otimes_\mathbb Z\mathcal O\mathbb A^n$ is exact and commutes with finite limits.