I have seen most books give this fact $f:X \to Y$ and $g:Y \to Z$ and $g\circ f : X \to Z$ is surjective , then it surely implies g is surjective.
Consider a more general case of $f:X \to Y$ and $g:W \to Z$ and that $g\circ f : X \to Z $ is surjective then if $g$ is also surjective then on what conditions must be imposed on $f[X] ,Y$ and $W$ such that its always true.
My thinking if $Y = W $ then its true from the fact i said earlier . Now consider $Y$ $\ne$ $W$ in that case i think if we have $f[X] \subseteq W$ , then we can set $A$ = $f[X]$ $\cap$ $W$ and then $f:X \to A$ and $g:A \to Z$ satisfies the earlier fact and hence this too is surjective ? So the only condition needed is $f[X] \subseteq W$ is this correct ?
When one writes "$f: X \to Y$" it does not necessarily imply that $f$ is surjective onto $Y$. So the first sentence is already general, since $f(X)$ might not be all of $Y$.
But if you insist on using your more general setup, you are correct that we only need $f(X) \subseteq W$. But this is automatically given, since it is a requirement in order to define $g \circ f$.