I'm reading through Aluffi's Algebra Chapter 0 and one of the exercises is to come up with a definition of an epimorphism and show that a map $f \colon A \to B$ is surjective iff it is an epimorphism.
In hindsight it's obvious to say that (Definition 1) $f$ is an epimorphism if for all maps $g_1, g_2 \colon B \to Z$, if $g_1 \circ f = g_2 \circ f$, then $g_1 = g_2$ (right-cancellation).
However, when I first approached the problem I had something about existence in mind and I came up with the following diagram:
Here, I wanted to define an epimorphism as follows: (Definition 2) $f$ is an epimorphism if for all maps $g \colon Z \to B$, there exists a map $h \colon Z \to A$ such that $g = f \circ h$.
In that case, a proof would go as follows (I will assume all sets $A,B,Z$ are nonempty):
Suppose $f$ is surjective. Then, for all $b \in B$, the preimage $f^{-1}(\{b\})$ is nonempty, so we can pick an element $a_b \in A$ such that $a_b \overset{f}{\mapsto} b$. Now if $z \overset{g}{\mapsto} b$ for $z \in Z$, then we can let $h(z)=a_b$. We can repeat this exercise for any $b' \in B$ that is mapped to under $g$.
On the other hand, suppose $f$ is an epimorphism according to Definition 2. Choose an element $b \in B$ and let $g$ be the constant map $g(z) \equiv b$. Then there exists a map $h \colon Z \to A$ such that $f(h(z))=g(z)=b$, so there is some $a \in A$ mapping to $b \in B$ under $f$. Again we can repeat this for any $b' \in B$.
Question 1 Is my proof correct and the definition sound?
Question 2 If the answer to Q1 is yes, then I assume I didn't just invent some new property in category theory but rather that this is some property that possibly has a name. (Would it qualify as a universal property?)

Your definition doesn't work in general, basically because of algebraic obstructions.
For instance, imagine $f : \mathbb{Z} \to \mathbb{Z}/2$ is the usual "reduce mod $2$" map in the category of groups. Then taking $g : \mathbb{Z}/2 \to \mathbb{Z}/2$ to be the identity map, we have a picture like yours, but notice there is no map $h : \mathbb{Z}/2 \to \mathbb{Z}$ making the diagram commute. In fact, the only group homomorphism $\mathbb{Z}/2 \to \mathbb{Z}$ is the trivial homomorphism. I'll let you explicitly work through why your proof doesn't work on this example, because I think it will be a good exercise ^_^.
However, you're not far off from a very useful criterion! We say that $Z$ is a projective object in a category if for every epimorphism $f : A \twoheadrightarrow B$ and every map $g : Z \to B$, we have a lift $h : Z \to A$ making the triangle commute. Notice this is a condition on $Z$, rather than a condition on $f$! In $\mathsf{Set}$, every object is projective (this is equivalent to the axiom of choice) so we can always detect epimorphisms by checking if a lift exists! Unwinding the fancy words gives basically the same proof that you gave (which does work in the category of sets), but it fails in other categories because of the lack of projectives.
I hope this helps ^_^