ag.algebraic geometry – Epi-mono factorisations in schemes via scheme-theoretic image

Suppose that $f : X rightarrow Y$ is a morphism of schemes.
Let $Z hookrightarrow Y$ the scheme-thereotic image of $f$.
Under what conditions is the morphism $X rightarrow Z$ an epimorphism?

If both $X = mathrm{Spec} , B$ and $Y = mathrm{Spec} , A$ are affine, then $Z = mathrm{Spec}, A/I$, where $I$ is the kernel of $A rightarrow B$. Then $A/I rightarrow B$ is injective, hence a monomorphism. Therefore $X rightarrow Z$ is an epimorphism.

I would think that if $f$ is quasi-compact or $X$ is integral, the scheme theoretic image has nice properties ($f(X)$ is dense in $Z$) and hopefully the result is true.