Proof (homotopic maps are preserved by composition)
Suppose $f_0 \simeq_H f_1$ and $g_0 \simeq_{H'} g_1$.
We'll apply transitivity to $$ \begin{align*} g_0 \circ f_0 \simeq g_0 \circ f_1 \simeq g_1 \circ f_1. \end{align*} $$
-
$g_0\circ f_0 \simeq g_0 \circ f_1$ via the homotopy $g_0\circ H$.
-
$g_0\circ f_1 \simeq g_1 \circ f_1$ via the homotopy $H'\circ (f_1 \times \id_{[0,1]})$.