**Proof.**
It follows from Remark 4.1.1.8 that $q \circ p$ is an inner fibration. Let us say that an edge $e$ of $X$ is *special* if $e$ is $p$-cartesian and $p(e)$ is $q$-cartesian. Remark 5.1.1.6 guarantees that every special edge of $X$ is $(q \circ p)$-cartesian. Consequently, to prove the first assertion, it will suffice to verify the following:

To prove $(\ast )$, set $y = p(x)$. Using our assumption that $q$ is a cartesian fibration, we can choose a $q$-cartesian edge $\widetilde{e}: y' \rightarrow y$ of the simplicial set $Y$ satisfying $q( \widetilde{e} ) = \overline{e}$. Using our assumption that $p$ is a cartesian fibration, we can choose a $p$-cartesian edge $e: x' \rightarrow x$ of $X$ satisfying $p(e) = \widetilde{e}$. Then $e$ is a special edge of $X$ satisfying $(q \circ p)(e) = q( \widetilde{e} ) = \overline{e}$.

To complete the proof, it will suffice to show that every $(q \circ p)$-cartesian edge $f: x'' \rightarrow x$ of $X$ is special. Let $\overline{f}: z'' \rightarrow z$ be the image of $f$ under $(q \circ p): X \rightarrow Z$. Using $(\ast )$, we can choose a special edge $e: x' \rightarrow x$ satisfying $(q \circ p)(e) = \overline{f}$. Since $e$ is $(q \circ p)$-cartesian, we can choose a $2$-simplex $\sigma $ of $X$ satisfying

\[ d_0(\sigma ) = e \quad \quad d_1(\sigma ) = f \quad \quad (q \circ p)(\sigma ) = s_0( \overline{e} ). \]

Set $g = d_2(\sigma )$, so that we can view $\sigma $ informally as a diagram

\[ \xymatrix@R =50pt@C=50pt{ & x' \ar [dr]^{ e } & \\ x'' \ar [ur]^{g} \ar [rr]^{f} & & x. } \]

Set $y' = p(x') \in Y$ and $z' = q(y') \in Z$. Since $f$ is $(q \circ p)$-cartesian, the edge $g$ is an isomorphism in the $\infty $-category $X_{z'}$ (Remark 5.1.3.8). Then $g$ is $p'$-cartesian, where $p': X_{z'} \rightarrow Y_{z'}$ is the projection map (Proposition 5.1.1.8). Applying Remark 5.1.3.5, we conclude that $g$ is locally $p$-cartesian. Since $p$ is a cartesian fibration, it follows that $g$ is $p$-cartesian (Remark 5.1.4.5). Invoking Proposition 5.1.4.12, we deduce that $f$ is also $p$-cartesian. Since $p(g)$ is an isomorphism in the $\infty $-category $Y_{z'}$, it is $q$-cartesian (Proposition 5.1.4.11). Applying Proposition 5.1.4.12, we conclude that $p(f)$ is also $q$-cartesian.
$\square$