Suppose $f\colon Y\to X$ is a morphism of schemes. Suppose $Z\hookrightarrow X$ is a closed subscheme defined by the quasi-coherent ideal $\mathcal J\subset \mathcal O_X$. The Stacks Project claims that $f$ factors through the inclusion $Z\hookrightarrow X$ precisely if the morphism $f^\ast \mathcal J\to f^\ast \mathcal O_X=\mathcal O_Y$ is the zero morphism. As far as I can tell, this is equivalent to the condition that $\mathcal J\hookrightarrow \mathcal O_X\to f_\ast \mathcal O_Y$ is the zero morphism, since the adjunction should preserve the zero morphisms.
However, this is never stated anywhere, which makes me suspicious, since I find my condition more straightforward than the one on the Stacks Project, so I don't know why it is not mentioned.
I would very much appreciate if anybody is willing to verify (or falsify) my thoughts.