In answering this question from Hartshorne, we ultimately end up using the following diagram
$$\require{AMScd} \begin{CD} X \times_Z Y @>{}>> Y\\ @V{}VV @VV{g}V \\ X @>{g\ \circ f}>> Z \end{CD}$$
and it occurred to me to look for an example where $X \times_Z Y \to Y$ is not the same as $f$. What I mean by this is that
$$\require{AMScd} \begin{CD} X @>{f}>> Y\\ @V{1_X}VV @VV{g}V \\ X @>{g\ \circ f}>> Z \end{CD}$$ clearly commutes, but if it were actually the pullback in full generality, then we could directly prove that a property enjoyed by $g \circ f$ is enjoyed by $f$ so long as that property is preserved under pullbacks.
So it must be the case that for some choices of $X, Y, Z, g, f$, and some test objects $T$ with morphisms $\phi : T \to Y$ and $\psi : T \to X$, there is more than one morphism $T \to X$ making the diagram commute ($\phi$ is always one choice). Further, replacing $X$ by $X \times_Z Y$ should fix this problem.
I'm not very good at this point at coming up with concrete examples of schemes to illustrate various concepts, so can someone share a good example where $X$ is not the fiber product in the second square? Ideally we would have an example where we can write down the maps $\phi, \psi$ that show that $X$ is not the fiber product, and see how passing to $X \times_Z Y$ fixes the possibility of multiple morphisms into $X$.
Suppose there exists an object $T$ with maps $\phi:T\to Y$ and $\psi:T\to X$ such that $g\circ f \circ\psi = g\circ \phi$. If $\alpha:T\to X$ is a map making the diagram commute, then we must have $1_X\circ \alpha = \psi$ and $\phi=f\circ \alpha$. As $1_X\circ\alpha=\alpha$, we must have $\alpha=\psi$ (not $\phi$, as written in your post), and we must also have that $\phi=f\circ\psi$, which is not guaranteed. In particular, the error is the opposite of what you've identified in your post: there's always at most one morphism making the diagram commute, but there may be no morphisms making it commute.
Here's an example: let $Z=\operatorname{Spec} k$, $Y$ the affine line with two origins over $k$, $g:Y\to Z$ the obvious map, $X=\Bbb A^1_k$, and $f:X\to Y$ the inclusion which hits only one of the two doubled origins. Let $T=\operatorname{Spec} k$ with $\psi$ the closed immersion of the origin and $\phi$ the closed immersion picking out the origin which isn't in the image of $f$. Then $g\circ f \circ \psi$ and $g\circ\phi$ are both the identity on $\operatorname{Spec} k$, but $\phi\neq f\circ\psi$. Therefore your second diagram is not always a pullback diagram.