Here's a counterexample that works in (almost) any category : let $p:X\to Y$ be a split epimorphism that is not an isomorphism, with section $s:Y\to X$. Then in the diagram
$$\require{AMScd}
\begin{CD}
Y @>{id_Y}>> Y @>{id_Y}>> Y\\
@V{id_Y}VV @VV{s}V @VV{id_Y}V\\
Y @>>{s}> X @>>_p> Y,
\end{CD}$$
the outer rectangle is a pullback since all its sides are identity maps, the left square is a pullback since $s$ is a monomorphism, but the right square cannot be a pullack if $s$ and $p$ are not isomorphisms.
Alternatively, you can take any monomorphism $m:A\to B$, and form the diagram
$$\require{AMScd}
\begin{CD}
A @>{id_A}>> A @>{m}>> B\\
@V{id_A}VV @VV{m}V @VV{id_B}V\\
A @>>{m}> B @>>_{id_B}> B.
\end{CD}$$
Here the left square is a pullback since $m$ is a mono, the rectangle is a pullback, but the right-hand square is not a pullback if $m$ is not an isomorphism.