Morphism epimorphism if and only if surjective
If $f:X\to Y$ is an epimorphism, define $g_1:Y\to\{0,1\}$ with $g_1(y)=0$ for all $y\in Y$, and $$g_2(y)=\begin{cases}0&y\in\mathrm{im}(f)\\1&\text{otherwise}\end{cases}$$
Then for $x\in X$ we see that $g_1\circ f (x)=0= g_2\circ f(x)$. From the property of epimorphism, this means that $g_1=g_2$, which is only possible if $\mathrm{im}(f)$ is all of $Y$.
Now, if $f$ is surjective, then take $g_1,g_2:Y\to Z$ with $g_1\circ f = g_2\circ f$. Then for any $y\in Y$, we can find $x\in X$ such that $f(x)=y$. Then $$g_1(y)=g_1\circ f (x)=g_2\circ f(x)=g_2(y)$$
So $g_1=g_2$.
I will give a constructive (or, more precisely, intuitionistic) proof.
First, the easy direction: surjective maps are epimorphisms. Indeed, if $f : X \to Y$ is surjective and $g_0 \circ f = g_1 \circ f$, then $g_0 = g_1$, i.e. for every $y \in Y$, $g_0 (y) = g_1 (y)$, because there is $x \in X$ such that $y = f(x)$ and therefore $g_0 (y) = g_0 (f (x)) = g_1 (f (x)) = g_1 (y)$.
Now, the harder direction: epimorphisms are surjective. Suppose $f : X \to Y$ is an epimorphism. Let $\Omega$ be the set of subsets of $\{ 0 \}$, let $g_0 : Y \to \Omega$ be the constant map with value $\{ 0 \}$, and let $g_1 : Y \to \Omega$ be defined as follows: $$0 \in g_1 (y) \iff \exists x \in X . f (x) = y$$ By construction, $g_0 \circ f = g_1 \circ f$; but then $g_0 = g_1$, so for every $y \in Y$, there is $x \in X$ such that $f (x) = y$, i.e. $f : X \to Y$ is surjective.
Some hints:
For epic $\Rightarrow$ surjective, let $Y=B \cup \{ \star \}$ (where $\star \not \in B$), let $\beta$ be the identity on $B$, and let $\beta'$ be the map which sends everything in the image of $\phi$ to itself, and everything not in the image of $\phi$ to $\star$. See what happens.
For surjective $\Rightarrow$ epic, just show that if $\beta,\beta' : B \to Y$ and $\beta \circ \phi = \beta' \circ \phi$, then $\beta(b)=\beta'(b)$ for all $b \in B$. Use the fact that $\phi$ is surjective to write a given $b \in B$ in a more useful way.