In order to formulate the question we need a couple of notions. (All rings mentioned are unital and nonzero, all modules are unitary.)
Let $k$ be a ring, $A$ a $k$-module, and $f\colon A\to S$ a function from the module $A$ to a set $S$. We say that $f$ does not depend on a submodule $W$ of $A$ if $f(a+w)=f(a)$ for all $a\in A$ and all $w\in W$. The kernel of $f$ is defined as the subset $\ker_k(f)$ of $A$ consisting of all $z\in A$ such that $f(a+\lambda z)=f(a)$ for all $a\in A$ and all $\lambda\in k\,$; $\ker_k(f)$ is the largest submodule of $A$ on which $f$ does not depend. In case when $A$ is just an abelian (additive) group (a $\mathbb{Z}$-module), the kernel of $f$ is $\ker_{\mathbb{Z}}(f)=\{z\in A\mid\text{$f(a+z)=f(a)$ for all $a\in A$}\}$.
We say that a ring $R$ is spanned by units if every element of $R$ is a sum of units of $R$.
Now consider the following lemma:
Let $R$ be a ring, $M$ a (multiplicatively written) monoid, and $N\colon R\to M$ a homomorphism of multiplicative monoids. If $R$ is spanned by units, then $\ker_{\mathbb{Z}}(N)$ is a two-sided ideal of $R$.
Proof. $~$We know that $Z:=\ker_{\mathbb{Z}}(N)$ is a subgroup of the additive group $R$. Let $z\in Z$. If $u$ is a unit of $R$ and $r\in R$, then $N(r+uz)=N(u)N(u^{-1}r+z)=N(u)N(u^{-1}r)=N(r)$, thus $uz\in Z$; since $R$ is spanned by units, we have $sz\in Z$ for every $s\in R$. Similarly we prove that $zs\in Z$ for every $s\in R$.$~$ Done.
Question(s). $~$After proving the lemma, I naturally wanted to check that the condition that $R$ be spanned by units cannot be omitted. However, for the life of me I am unable to find an example of $R$, $M$, $N$ as in the first statement of the lemma, but with the ring $R$ not spanned by units and with $\ker_{\mathbb{Z}}(R)$ not an ideal of $R$. Can you help me out here, one way or another -- either by finding an example demonstrating that the condition that $R$ is spanned by units cannot be omitted, or by coming up with a proof which does not need the condition? Perhaps the condition can be replaced by some weaker condition?
Remarks. $~$The lemma above is just a fragment of a wider story. For one thing, the lemma can be augmented by the following statement:
With everything as in the lemma, if $N$ has the additional property that for every $r\in R$,
$N(r)$ invertible in $M$ implies $r$ invertible in $R$, then the ideal $\ker_{\mathbb{Z}}(N)$ is contained in the Jacobson radical of $R$.
Proof. $~$For every $z\in\ker_{\mathbb{Z}}(N)$, $N(1+z)=N(1)=1$ is invertible, thus $1+z$ is a unit.$~$ Done.
In certain interesting situations the kernel of $N$ is the Jacobson radical $J$ of $R$. In such a case $N$ factors through the natural projection $p\colon R\to R/J$ as $N=\overline{N}\circ p$, where the (unique) function $\overline{N}\colon R/J\to M$ is a homomorphism of multiplicative monoids, and $R/J$ is Jacobson-semisimple.