Solution (source code)

= Solution

Work over an <affine open subscheme> $V=\operatorname{Spec}A$ of $Z$. Since $g$ is a <closed immersion>, its inverse image is $\operatorname{Spec}(A/I)$ for some ideal $I$. Since $f$ is a <closed immersion>, the inverse image of this <affine scheme> in $X$ is $\operatorname{Spec}((A/I)/J)$ for an ideal $J\subseteq A/I$. Let $\widetilde J$ be the inverse image of $J$ in $A$. The composite on this open is induced by the surjection
$$
A\longrightarrow(A/I)/J\simeq A/\widetilde J.
$$
The affine-local characterization from part (a) therefore shows that \b[$g\circ f$ is a <closed immersion>]. In particular, closed-subscheme ideals compose by taking the inverse image of the second quotient ideal.