By definition, both compositions are maps $X \to Z$, so it remains to show that the values of both compositions coincide on each element of $X$. If $x \in X$, then
\begin{equation}
\begin{split}
(h \circ (g \circ f))(x)
= h((g \circ f)(x))
& = h(g(f(x))) \\
& = (h \circ g)(f(x))
= ((h \circ g) \circ f)(x)
\end{split}
\end{equation}
Hence, the claim is now a consequence of
R1869: Characterisation of equality of maps. $\square$