Q:

Do certain maps between f.g. $\mathbb{C}$-algebras factor through a local (and f.g.) algebra?

(Intuition: in the category of non-empty sets, every function that coequalizes all points in the domain factors through the terminal object. I would like to know if something analogous happens in certain category of `connected algebraic spaces'.
I formulate the precise question in terms of commutative algebra.)
Let $\cal A$ be the category of finitely generated $\mathbb{C}$-algebras with exactly two idempotents.
Let ${f : A \rightarrow B}$ be a map in $\cal A$ such that, for every ${g, h : B \rightarrow \mathbb{C}}$, ${g f = h f : A \rightarrow \mathbb{C}}$.
Does $f$ factor (inside $\cal A$) as ${f = k l}$ with ${l : A \rightarrow L}$, ${k : L \rightarrow B}$ and $L$ local?

A:

Yes it's true.
1) First assume that $B$ is reduced (non nonzero nilpotent element). Let $I$ be the set of maximal ideals of $B$. Since for a f.g. algebra over a field, the Jacobson radical equals the radical, we have $\bigcap_{M\in I}M=0$. By the Nullstellensatz, for every $M\in I$ there is a unique $\mathbf{C}$-algebra homomorphism $u=u_M:B\to\mathbf{C}$ such that $\mathrm{Ker}(u)=M$. Thus we have a canonical embedding $j=(u_M)_{M\in I}$ of $\mathbf{C}$-algebras $B\to\mathbf{C}^I$.
I claim that $j(f(A))$ is valued in the diagonal of $\mathbf{C}^I$ (the constant maps $I\to\mathbf{C}$). Indeed otherwise this means that $j(f(A))$ contains a nonconstant map, which means that there exist $M,M'\in I$ and $a\in A$ such that $u_M(f(a))\neq u_{M'}(f(a))$. So $u_M\circ f\neq u_{M'}\circ f$. This precisely contradicts the assumption.
So $j(f(A))$ is contained in the diagonal (i.e., in the scalars of $\mathbf{C}^I$). Since $j$ is injective, this means that $f(A)$ is contained in the scalars. Hence the conclusion holds (with $L=\mathbf{C}$).
2) In general, let $R$ be the nilradical of $B$. Then the composite map $A\to B/R$ clearly satisfies the assumption, so is valued in the scalars. This means that $f(A)=(f(A)\cap R)\oplus\mathbf{C}1_B$, where the direct sum is in terms of vector spaces. This implies that $f(A)$ has Krull dimension zero (since its nilradical is a hyperplane, see details in edit below) and actually that $L=f(A)$ is local artinian.  
Note: the assumption on idempotents seems unnecessary.
Conclusion: 

For every algebraically closed field $K$, and $f:A\to B$ homomorphism of finitely generated (commutative associative unital) $K$-algebra we have equivalences 

$g_1f=g_2f$ for all $g_1,g_2$ $K$-algebra homomorphisms $B\to K$
$f(A)$ is local (artinian)
$f$ factors through a local finitely generated $K$-algebra (i.e., a commutative $K$-algebra that is local and of finite dimension as $K$-module).

Edit (to answer the OP's request in the comment)
Proposition: let $K$ be a field and $D$ a commutative $K$-algebra. Suppose that the nilradical $N$ of $D$ is a hyperplane. Then $D$ is local artinian. 
Proof: since on an arbitrary commutative ring every prime ideal contains the nilradical, it follows from the assumption that $N$ is the only prime ideal, and thus $D$ is artinian. Also it follows that $N$ is the unique maximal ideal, and hence $D$ is local.

