Let $\varphi: R \rightarrow S$ be a (unital) ring homomorphism. So every left $S$-module $M$ has also a left $R$-module structure via $\varphi$ and in general we have $ \text{End}_S(M) \subseteq \text{End}_R(M)$ My question is: Is there a necessary and sufficient condition on $\varphi$ such that the above inclusion becomes an equality for every $M$?
Note that $\varphi$ being surjective is sufficient but not necessary as $\mathbb{Z} \hookrightarrow \mathbb{Q}$ also has the desired property. This led me to believe $\varphi$ being an epimorphism in the category $\mathsf{Ring}$ is the condition I want but I couldn't show that or find a counterexample.
Edit: We can generalize the situation with $\mathbb{Z} \hookrightarrow \mathbb{Q}$: If $R$ is commutative and $D$ is a multiplicatively closed subset of $R$, the localization $R \rightarrow D^{-1}R$ has the desired property.
Moreover ring homomorphisms with this "equal endomorphisms" property are closed under composition. So any composition of surjections and localizations also works. Unfortunately there are commutative ring epimorphisms which cannot be factored to surjections and localizations, as can be seen here. (Some time I will try to work out some of the examples given there to see whether they fail to equalize the endomorphisms or not)
Edit: In general a necessary condition is that the centralizer of the image $\varphi(R)$ in $S$ should be equal to the center of $S$:
We always have $\mathbf{Z}(S) \subseteq \mathbf{C}_{S}(\varphi (R))$. For the reverse inclusion, let $u \in \mathbf{C}_S(\varphi(R))$. Then letting M be the left regular $S$-module $_S S$, the map $\alpha: S \rightarrow S$ given by $\alpha(s) = us$ lies in $\text{End}_R(M)$.
Now by assumption $\alpha$ is also an $S$-endomorphism. We know that $S$-endomorphisms of $M$ are right multiplications by elements of $S$. Say $\alpha$ is given by right multiplication by $t \in S$. Then evaluating at $1$, we get $u = t$. Thus left and right multiplications by $u$ coincide, that is $u \in \mathbf{Z}(S)$.
Note that by above, when $R$ is commutative we get $\varphi(R) \subseteq \mathbf{C}_S(\varphi(R)) = \mathbf{Z}(S)$ This means $S$ is an $R$-algebra via $\varphi$.
So in this case the question can be rephrased as "Let $k$ be a commutative ring and $S$ be a $k$-algebra. When can we say that $k$-linear endomorphisms of $S$-modules are always $S$-linear?" Maybe this has an easy answer when $k$ is a field.
A relevant (perhaps more natural) question to mine is when all homomorphisms are the same, not just endomorphisms. That is, can we find a (nice) condition on $\varphi$ such that for every pair of $S$-modules $M$ and $N$ the inclusion $\text{Hom}_S(M,N) \subseteq \text{Hom}_R(M,N)$ becomes an equality?