[proofplan]
We prove both implications directly from the categorical definition of an epimorphism. If $e$ is surjective, then equality after precomposition with $e$ forces two functions out of $B$ to agree at every element of $B$. Conversely, if $e$ misses an element $b_0 \in B$, we construct two distinct functions $B \to \{0,1\}$ that agree on the image of $e$, so their composites with $e$ are equal although the functions themselves are not.
[/proofplan]
[step:Use surjectivity to cancel precomposition by $e$]
Assume that $e: A \to B$ is surjective. To prove that $e$ is an epimorphism in $\mathbf{Set}$, let $Y$ be a set and let
\begin{align*}
u: B &\to Y,\\
v: B &\to Y
\end{align*}
be functions such that
\begin{align*}
u \circ e = v \circ e.
\end{align*}
We must prove $u=v$.
Let $b \in B$. Since $e$ is surjective, there exists $a \in A$ such that $e(a)=b$. Evaluating the equality $u \circ e = v \circ e$ at this element $a$ gives
\begin{align*}
u(b)
=
u(e(a))
=
(u \circ e)(a)
=
(v \circ e)(a)
=
v(e(a))
=
v(b).
\end{align*}
Since $b \in B$ was arbitrary, $u$ and $v$ agree on every element of $B$. Hence $u=v$ as functions $B \to Y$. Therefore $e$ is an epimorphism in $\mathbf{Set}$.
[/step]
[step:Construct two distinct maps when $e$ is not surjective]
Assume that $e: A \to B$ is not surjective. Then there exists an element $b_0 \in B$ such that no element of $A$ maps to $b_0$:
\begin{align*}
\forall a \in A,\quad e(a) \ne b_0.
\end{align*}
Let $Y := \{0,1\}$. Define functions
\begin{align*}
u: B &\to Y,\\
b &\mapsto 0
\end{align*}
and
\begin{align*}
v: B &\to Y,\\
b &\mapsto
\begin{cases}
1, & b=b_0,\\
0, & b \ne b_0.
\end{cases}
\end{align*}
For every $a \in A$, the choice of $b_0$ gives $e(a) \ne b_0$, so
\begin{align*}
(u \circ e)(a)
=
u(e(a))
=
0
=
v(e(a))
=
(v \circ e)(a).
\end{align*}
Thus $u \circ e = v \circ e$ as functions $A \to Y$.
However,
\begin{align*}
u(b_0)=0
\qquad\text{and}\qquad
v(b_0)=1,
\end{align*}
so $u \ne v$ as functions $B \to Y$. Therefore precomposition with $e$ is not cancellative on maps out of $B$, and $e$ is not an epimorphism in $\mathbf{Set}$.
[/step]
[step:Combine the two implications]
The first step proves that every surjective function $e: A \to B$ is an epimorphism in $\mathbf{Set}$. The second step proves the contrapositive of the reverse implication: if $e$ is not surjective, then $e$ is not an epimorphism in $\mathbf{Set}$. Hence $e$ is an epimorphism in $\mathbf{Set}$ if and only if $e$ is surjective.
[/step]