Let $f:X\to B$ be a stable curve of genus $g$ over a finite type integral $\mathbb C$-scheme.
Lemma 1. The moduli map $B\to \bar {M_g}$ is constant if and only if there exists a dense open $U$ of $B$ such that all fibers of $X$ over $U$ are isomorphic.
Proof. (Compare with jmc's comment.) If $B\to \bar{M_g}$ is constant, then the fibers of $X\to B$ are all isomorphic (by definition). So take $U=B$. Conversely, if all fibers over (some dense open) $U$ are isomorphic, then $U\to \bar {M_g}$ is constant. The extension of the moduli map to $B$ (which exists by assumption) is then also constant. QED
Now, to answer your question, as Laurent Moret-Bailly points out, you need some regularity hypothesis as well.
Theorem. Suppose that $X$ is non-singular. Then the moduli map $B\to \bar {M_g}$ is constant if and only if there exists a dense open $U$ of $B$ such that all fibers of $X$ over $U$ are smooth and isomorphic.
Proof. Since $X$ is nonsingular, the morphism $X\to B$ is smooth over some open $U$. In particular, if $B\to \bar{M_g}$ is constant, then its image lies in $M_g$. Conversely, apply the lemma with $B$ replaced by $U$. QED