I realize that there has already been an answer to this problem. But I want to know if my proof was correct. Thank you for your time.
Suppose A,B, and C are sets and $f: A \rightarrow B$
Suppose that C has at least two elements, and for all functions $g$ and $h$ from B to C, if $g \circ h = h \circ f$ then $g = h$. Prove that $f$ is onto.
Suppose f is not onto. Then there is $b_1$ such that for all $a \in A$, $f(a) \neq b_1$. Suppose $(b_1, c_1) \in g$ and $(b_1, c_2) \in h$. For the assumption that $g \circ h = h \circ f$ then $g = h$ to be true, $(b_1, c_1) = (b_1, c_2)$ whenever $g \circ f = h \circ f $.
Assume $g \circ f = h \circ f$. Since $b_1 \notin Ran(f)$, $(a,c_1) \notin g \circ f$ and $(a,c_2) \notin h \circ f$. This means that as long as there are at least two elements in C, it is possible that $(b_1, c_2) \neq (b_1, c_2)$ while $g \circ f = h \circ f$. (Even if $c_1 \neq c_2$, it can still be true that $g \circ f = h \circ f$ since $c_1$ and $c_2$ are not in the range of $g \circ f$ and $h \circ f$.)
This is a contradiction, hence $f$ is onto.