Solution (source code)

= Solution

Since $g$ is a <separated morphism>, the <diagonal morphism> $\Delta_g:Y\to Y\times_ZY$ is a <closed immersion>. The square
$$
\begin{array}{ccc}
X&\xrightarrow{\Gamma_f}&X\times_ZY\\
{\scriptstyle f}\downarrow&&\downarrow{\scriptstyle(f\circ p_X,p_Y)}\\
Y&\xrightarrow{\Delta_g}&Y\times_ZY
\end{array}
$$
is cartesian. Indeed, on test schemes its pullback condition is $(f(x),y)=(t,t)$, forcing $y=t=f(x)$, and leaving exactly the choice of $x$. The <graph morphism of schemes> $\Gamma_f$ is therefore a <base change of a morphism of schemes> of $\Delta_g$. Part (c) shows that \b[$\Gamma_f$ is a <closed immersion>].

Now assume additionally that $h=g\circ f:X\to Z$ is a <closed immersion>. The projection $p_Y:X\times_ZY\to Y$ is its <base change of a morphism of schemes> along $g$, so is a <closed immersion> by part (c). Since
$$
\boxed{f=p_Y\circ\Gamma_f,}
$$
part (b) shows that \b[$f$ is a <closed immersion>]. This covers the further assumption in the final unheaded paragraph.