Problem statement, as written:
Let $f\colon A \rightarrow C$ and $g\colon A \rightarrow B$ be functions. Prove that there exists a function $h\colon B \rightarrow C$ such that $f = h \circ g$ if and only if $\forall x,y \in A$, $g(x) = g(y) \rightarrow f(x) = f(y)$. Prove that $h$ is unique.
The theorem is vacuously true if any of $A,B,C$ are empty. Thus, $A,B,C \ne \emptyset$. As such, let $c_0 \in C$. Define $h\colon B \rightarrow C$ by $h = \{(b,c)|\exists x \in A$ such that $b = g(x)$ and $c = f(x)\}$ $\cup$ $\{(b,c_0) | b \in \{B -\{g(a) | a \in A\}\}\}$.
To see that $h$ satisfies the definition of function, we show that 1) $dom(h) = B$, 2) $ran(h) \subseteq C$, and 3) $(x,y_1),(x,y_2) \in h \rightarrow y_1 = y_2$.
To prove 1), first, let $b \in dom(h)$. Then by the definition of $h$, $\exists a \in A$ such that $b=g(a)$. But $g\colon A \rightarrow B$,so $g(a) = b \in B$. So $dom(h) \subseteq B$. To prove the converse, let $b\in B$. Note since $g\colon A \rightarrow B$, either $\exists a \in A$ such that $b = g(a)$, or $\forall a\in A, b \ne g(a)$. Thus, we break the proof into two exhaustive cases. Case 1) $ \exists a\in A$ such that $ b = g(a)$. Then by the definition of $h$, $b \in dom(h)$. So this case results in $B \subseteq dom(h)$. Case 2) $ \forall a \in A, b \ne g(a)$. This time, by the definition of $h$, $(b,c_0) \in h$, so again, we have that $b\in dim(h)$. This case also results in $B \subseteq dom(h)$. Thus, $B = dom(h)$. To prove 2), let $c \in ran(h)$. Then by the definition of $h$, $\exists a \in A$ such that $c = f(a)$. Since $f\colon A \rightarrow C$, $f(a) = c \in C$. Thus, $ran(h) \subseteq C$. Lastly, to show 3), assume $(x,y_1),(x,y_2) \in h$. Then by the definition of $h$, $\exists a\in A$ such that $x = g(a)$. Furthermore, $y_1 = f(a) = y_2$. Thus, in particular, $y_1 = y_2$. In other words, every domain element is mapped to a (unique) range element.
Now we prove the biconditional statement form of the theorem. $(\rightarrow)$ Suppose $f=h\circ g$. Let $x,y \in A$ and assume $g(x) = g(y)$. Then $(h \circ g)(x) = h(g(x)) = f(x)$. Since $g(x) = g(y), h(g(x)) = h(g(y)) = f(y)$ (The rightmost equalities in each of the preceding two strings of equalities are a result of applying the definition of $h$). Thus, in particular, $f(x) = f(y)$, as desired. $(\leftarrow)$ Now suppose $\forall x,y \in A, g(x) = g(y) \rightarrow f(x) = f(y)$. To see that $f = h\circ g$, take $a \in A$. $(h \circ g)(a) = h(g(a)) = f(a)$, where the last equality, again, follows from the definition of $h$.
To see that $h$ is unique, suppose $l$ is any other function such that $f = l \circ g$ if and only if $\forall x,y \in A$, $g(x) = g(y) \rightarrow f(x) = f(y)$. To see that $h = l$, we proceed by contradiction. Thus, suppose (to the contrary) $l \ne h$. Then $\exists \beta \in B$ such that $h(\beta) \ne l(\beta)$. Since $g$ is surjective, by hypothesis, $\exists a_1 \in A$ such that $\beta = g(a_1)$; also, $h(\beta) = f(a_1) = c_1$. Suppose $x,y \in A$ and $g(x) = g(y)$. Then by the definition of $h$ applied to $g(x)$, we find that $f(x) = f(y)$. Thus we may conclude that $f = h \circ g$ and $f = l \circ g$, so $h\circ g = l\circ g$. Observe that $(a_1,c_1)\in f = h\circ g$, so $(a_1,c_1)\in h\circ g$. This means $\exists b_1 \in B$ such that $(a_1,b_1)\in g$ and $(b_1,c_1) \in h$. Recall, however, that $h\circ g = l\circ g$ also. Hence, $(a_1,c_1) \in l \circ g$. So $\exists b_* \in B$ such that $(a_1,b_*) \in g$ and $(b_*,c_1) \in l$. But since $g\colon A\rightarrow B, b_* = b_1$. Thus, as $\beta = g(a_1) = b_* = b_1$, $l(\beta) = c_1 = h(\beta)$, a contradiction. Therefore, it must be that $l = h$.