When does a (polynomial) ring homomorphism commute with scalar multiplication? Definitions: Let $k$ be an arbitrary field, $I$ a prime ideal of $k[x_1, \dots, x_n]$, $J$ a prime ideal of $k[y_1, \dots, y_m]$, $X = \{ x \in k^n: \forall f \in I, \ f(x) = 0\  \} \subset k[x_1, \dots, x_n]$, $Y=\{y \in k^m: \forall g \in J, \ g(y)=0  \}$, $\mathcal{O}_X = k[x_1,\dots,x_n]/I$, and $\mathcal{O}_Y = k[y_1, \dots, y_m]/J$.
(I.e. $X$ and $Y$ are affine varieties, and $\mathcal{O}_X$ and $\mathcal{O}_Y$ are their respective coordinate rings.)
Both $\mathcal{O}_X$ and $\mathcal{O}_Y$ are commutative rings with a multiplicative identity, so when considering a ring homomorphism $\varphi: \mathcal{O}_Y \to \mathcal{O}_X$ we will mean a function $\mathcal{O}_Y \to \mathcal{O}_X$ such that for all $g_1,g_2 \in \mathcal{O}_Y$ $\varphi(g_1+g_2)=\varphi(g_1)+ \varphi(g_2)$, $\varphi(g_1g_2)=\varphi(g_1)\varphi(g_2)$, and $\varphi(1+J)=1+I$.
Question: Under what conditions on the field $k$ is any ring homomorphism $\varphi: \mathcal{O}_Y \to \mathcal{O}_X$ a $k$-algebra homomorphism? I.e. under what conditions on the field $k$ does any ring homomorphism $\varphi: \mathcal{O}_Y \to \mathcal{O}_X$ commute with scalar multiplication, for all $c \in k, g \in k[y_1, \dots, y_m]$, $$\varphi(cg+J)=c\varphi(g+J)? $$ Because $k \subset k[x_1, \dots, x_n]$, $k\subset k[y_1, \dots, y_m]$, the above is equivalent to requiring, for all $c \in k$, that: $$\varphi(c+J) = c+I\,, $$ with the previously stated property following from the fact that $\varphi$ commutes with multiplication.
Attempt: In special cases, e.g. $k = \mathbb{Q}$ or $k=\mathbb{R}$, this should be true (provided in the latter case that $\varphi$ is also continuous, which I don't see why we can assume in general). For more general $k$, I don't see at all why this should be true, even if $\varphi$ is continuous.
For $k=\mathbb{Q}$, I think this follows from the facts that $\varphi(1+J)=1+I$, $\varphi(g_1g_2+J)=\varphi(g_1+J)\varphi(g_2+J)$, and that $\varphi((g_1+g_2)+J)= \varphi(g_1+J)+\varphi(g_2+J)$. Namely, $$\varphi(2+J) = \varphi((1+1)+J)=\varphi(1+J)+\varphi(1+J)=(1+I)+(1+I)=2+I\,, $$ and then by using induction we get that $\varphi(n+J)=n+I$ for all $n \in \mathbb{N}$.
Then for any $n \in \mathbb{Z}$, we get that $\varphi(n+J)=n+I$ because $\varphi(J)=I$ and $I=\varphi(J)=\varphi((n+(-n))+J)=\varphi(n+J)+\varphi(-n+J) \implies \varphi(n+J)=-\varphi(-n+J)$.
Then for any $q = \frac{m}{n} \in \mathbb{Q}$, we have that $$m+I=\varphi(m+J)=\varphi\left(\left(\frac{m}{n}\right)n+J\right)=\varphi\left(\frac{m}{n}+J\right)\varphi(n+J)=\varphi\left(\frac{m}{n}+J\right)(n+I)\\ \implies \varphi\left(\frac{m}{n}+J\right)=\frac{m}{n}+I\,.$$
Then, assuming that $\varphi$ is continuous, since any real $r \in \mathbb{R}$ is a limit of some sequence of rational numbers $\{q_n\}$, and continuous functions commute with limits of sequences, we get: $$ \varphi(r+J)=\varphi\left(\lim_{n \to \infty} (q_n+J)\right) = \lim_{n \to \infty} \varphi(q_n +J) = \lim_{n \to \infty} (q_n + I) = r+I\,. $$ Thus $\varphi(c+J)=c+I$ for all $c \in k$ for $k=\mathbb{R}$ (or $k=\mathbb{Q}$). (Related)
For $k=\mathbb{C}$, since $-1 \in \mathbb{Z}$, we have that: $$-1+I= \varphi(-1 +J)= \varphi(i^2 +J)= \varphi(i+J)^2 \implies \varphi(i+J) = \pm i +I \,. $$ Since the Galois group of $\mathbb{R}[i]$ is non-trivial, I don't see how it could be possible to exclude the possibility that $\varphi(i+J)=-i+I$. Similar problems would arise with other algebraic field extensions of $\mathbb{Q}$ or $\mathbb{R}$ (I imagine).
For fields without straightforward relationships to $\mathbb{Q}$, I imagine that this could fail to be true in even more dramatic ways, but I don't know, hence my question.
Context: This question is inspired by Problem 4.18.5 of Algebraic Geometry: A Problem Solving Approach by Garrity et al., which asks one to show that each ring homomorphism $\mathcal{O}_Y \to \mathcal{O}_X$ corresponds to a morphism between the affine varieties $X \to Y$, for $k$ an arbitrary field. The only way I could get a proof to work was with the additional assumption that $\varphi(c+J)=c+I$ for all $c\in k$, which as I noted above is equivalent to $\varphi$ commuting with scalar multiplication and thus being a $k$-algebra homomorphism. This seems to be corroborated by Problem 4.8.4 of the same book, Wikipedia, Theorem 4.14 here, and other references I remember finding.
Thus, I want to understand the extent of the strength of this additional assumption, and whether or not it actually follows for any fields $k$ from the fact that $\varphi: \mathcal{O}_Y \to \mathcal{O}_X$ is a ring homomorphism.
 A: I've been thinking about this some more and I realize I may have essentially already answered the question in the attempt. Essentially in what follows I will try to reduce the question as much as possible to one of field automorphisms of $k$.
It will actually help to expand the generality of the question -- thus, instead of just considering polynomial rings/algebras, in what follows, we will consider arbitrary associative and unital algebras over the field $k$ (not even necessarily commutative).

A unital associative algebra $A$ over the field $k$ can be considered a nonzero ring $A$ with multiplicative identity along with a ring homomorphism $\eta_A: k \to Z(A)$ (where $Z(A)$ is the center of $A$) such that $\eta_A(1_K)=1_A$. Scalar multiplication $k \times A \to A$ is then defined by $c f := \eta_A(c)f$.
In what follows we assume that every $k$-algebra is of this type and henceforth just write $k$-algebra without explicitly mentioning that it is unital and associative.
Then given two $k$-algebras $A$ and $B$, a k-algebra homomorphism $\varphi: A \to B$ is a ring homomorphism $A \to B$ such that $\varphi \circ \eta_A = \eta_B$ -- in particular, $\varphi(1_A)=1_B$.

Thus, we have reduced the question of whether $\varphi$ is a $k$-algebra homomorphism to the question of whether or not it satisfies the equation $\varphi \circ \eta_A = \eta_B$. (This is a necessary and sufficient condition.)
I believe we can do even more than this, however. Since $k$ is a field (and $A$ and $B$ are by assumption nonzero), the ring homomorphisms $\eta_A$ and $\eta_B$ are injective.
Therefore, $\eta_A(k) \cong k \cong \eta_B(k)$, i.e. the field $k$ embeds into $A$ and $B$. Then a necessary (I don't know whether it's sufficient) condition for $\varphi$ to be a $k$-algebra homomorphism is that $\varphi(\eta_A(k))=\eta_B(k)$, i.e. that $\varphi$ restricts to a ring homomorphism $\eta_A(k) \to \eta_B(k)$, which clearly turns out to be a field isomorphism. (In the above, this is written as $\forall c \in k, \varphi(c + J) = c+I $.)
Claim: The above necessary condition can fail if $k$ has a non-trivial Galois group. (If there are $k$ automorphisms which are not the identity.)
In other words, if all ring homomorphisms $\varphi: A \to B$ are to be $k$-algebra homomorphisms, it is a necessary condition that $k$ have trivial Galois group.
Proof: Since $\eta_A|_k$ and $\eta_B|_k$ are isomorphisms, they have inverses, $\psi_A: \eta_A(k) \to k$, $\psi_B: \eta_B(k) \to k$, respectively. It follows from this that $\psi_B \circ \varphi\circ \eta_A : k \to k$ is an automorphism of $k$.
If $\varphi$ is a $k$-algebra homomorphism, then $\varphi \circ \eta_A = \eta_B = (\psi_B)^{-1}$. Thus $\psi_B \circ( \varphi \circ \eta_A) = \psi_B \circ (\psi_B)^{-1} = \operatorname{Id}_k$.
If $k$ has non-trivial Galois group, then (I assume, but can't actually prove that) there exists a ring homomorphism $A \to B$ such that $\psi_B \circ \varphi \circ \eta_A \not= \operatorname{Id}_k$, so that not all ring homomorphisms $A \to B$ are $k$-algebra homomorphisms.
Note: The category of $k$-algebras and $k$-algebra homomorphisms as defined above is a coslice category, formed from the category of (not-necessarily-commutative) rings with identity.
Since any field automorphism of a field of characteristic zero fixes $\mathbb{Q}$, or more generally for any field of any characteristic the smallest subfield containing the multiplicative identity, $\mathbb{Q}$ has trivial Galois group as noted above. In this case the condition is also sufficient, not just necessary.
Here are other fields with trivial Galois group.
Remaining Questions:
1. Does $\varphi(1_A) = 1_B \implies \varphi(\eta_A(k))= \eta_B(k)$?
2. Does $\varphi(\eta_A(k))=\eta_B(k) \implies \varphi \circ \eta_A = \eta_B$?
3. Does ($k$ has a trivial Galois group) $\implies$ for all ring homomorphisms $\varphi:A \to B$, $$\varphi(\eta_A(k))=\eta_B(k)\,?$$
4. Does ($k$ has a trivial Galois group) $\implies$ for all ring homomorphisms $$\varphi \circ \eta_A = \eta_B? $$
