TITLE: Injectivity, surjectivity and pullback diagrams
QUESTION [7 upvotes]: Consider the following pullback diagram (in any category):
$$
\newcommand{\ra}[1]{\kern-1.5ex\xrightarrow{\ \ #1\ \ }\phantom{}\kern-1.5ex}
\newcommand{\ras}[1]{\kern-1.5ex\xrightarrow{\ \ \smash{#1}\ \ }\phantom{}\kern-1.5ex}
\newcommand{\da}[1]{\bigg\downarrow\raise.5ex\rlap{\scriptstyle#1}}
\begin{array}{c}
A \times_C B & \ra{p} & A \\
\da{q} & & \da{a} \\
B & \ras{b} & C \\
\end{array}
$$
with $a$ a monomorphism and $b$ an epimorphism. I would like to understand necessary and/or sufficient conditions for $p$ to be an epimorphism too.
The following might be relevant:

Lemma: $q$ is always a monomorphism (and dually, in all pushout diagrams, the same statement holds for the epimorphism)
Proof: Assume that we have two maps $u_1, u_2$ from some object $W$ to $A \times_C B$ such that $q \circ u_1 = q \circ u_2$. Then $a \circ p \circ u_1 = a \circ p \circ u_2$ because the diagram is Cartesian, and therefore $p \circ u_1 = p \circ u_2$ because $a$ in a monomorphism. But since $u_1$ and $u_2$ are uniquely determined by their compositions $p \circ u_i$ and $q \circ u_i$, and since both coincide, we have that $u_1 = u_2$, and therefore $q$ is a monomorphism. QED

I have read here a proof for Abelian categories, but I think that my proof should be ok for any category, am I wrong? Anyway, back to the main point:

Question: When is $p$ an epimorphism too?

I don't expect this to be always true. But maybe there are necessary and/or sufficient conditions for when this works. For instance, for Sets it is always true (just look at the explicit construction of the pullback).
PS: I have seen here that it is true in any Abelian category.

REPLY [3 votes]: A simple condition in a category which make epimorphisms stable under pullback is the following:

In a category with a projective generator, epimorphisms are stable under pullback.

Recall that as object $Z$ is a generator if for each pair of distinct parallel morphisms $f,g:X\to Y$ there exists a morphisms $x:Z\to X$ such that $xf\neq xg$.
An object $Z$ is projective if and only if for each epimorphism $e:X\to Y$ and each morphism $y:Z\to Y$ there exists a morphism $x:Z\to X$ such that $y=xe$.
This condition is fullfilled, for example:

in the category of sets by taking $\{\varnothing\}$ as projective generator;
in the cateogry of modules over a ring taking the ring itself as projective generator;
in the category of groups taking $\Bbb Z$ as projective generator.

proof. The proof of this fact follows at once by noting that given a projective generator $Z$, a morphism $f:X\to Y$ is an epimorphisms if and only if for all $y:Z\to Y$ there exists $x:Z\to X$ such that $y=xf$.
The only if part is follows since $Z$ is projective.
For the if part follows arguing by contradiction: if $f$ is not an epimorphism, then there exists a pair of distinct parallel arrows $u,v:Y\to W$ such that $fu=fv$.

Since $Z$ is a generator, there exists $y:Z\to Y$ such that $yu\neq yv$.
Let $x:Z\to X$ such that $xf=y$.
Then
$$yu=xfu=xfv=yv$$
a contradiction.
Now consider the pullback square below.
We claim that $q$ is epic.
Let $y:Z\to B$.
Then $yb:Z\to C$ and since $a$ is epic, there exists $x:Z\to A$ such that $yb=xa$.
Since the square is a pullback, there exists $z:Z\to P$ such that $y=zq$.