This may have some interest to students in algebraic geometry: Vakil's algebraic geometry notes on "schemes" gives this as an exercise (see exercise 1.3.s on page 37 in the attached link). Any scheme has an open cover of affine schemes and let us first prove it for affine schemes.
https://math.stanford.edu/~vakil/216blog/FOAGnov1817public.pdf
Let $A\rightarrow B$ be a map of commutative unital rings and let $C_1,C_2$ be commutative unital $B$-algebras. Let $m:B\otimes_A B \rightarrow B$ be the multiplication map and let $I:=ker(m)$. We want an explicit isomorphism
$$B\otimes_{B\otimes_A B}(C_1\otimes_A C_2) \cong C_1\otimes_B C_2.$$
Note that there is a canonical isomorphism
$$ B\otimes_{B\otimes_A B}(C_1\otimes_A C_2)\cong C_1\otimes_A C_2/I(C_1\otimes_A C_2)$$
where we view $C_1\otimes_A C_2$ as a left $B\otimes_A B$-module via the canonical map. The canonical map
$$C_1\otimes_A C_2 \rightarrow C_1\otimes_B C_2$$
induce a canonical map
$$F': B\otimes_{B\otimes_A B}(C_1\otimes_A C_2) \cong C_1\otimes_A C_2/I(C_1\otimes_A C_2) \rightarrow C_1\otimes_B C_2.$$
We want a map in the other direction: There is a canonical map
$$F: C_1\times C_2 \rightarrow C_1\otimes_A C_2/I(C_1\otimes_A C_2)$$
defined by
$$F(x,y):=\overline{x\otimes y}.$$
The map $f$ induce a map of rings $F$
$$F: C_1\otimes_B C_2 \rightarrow C_1\otimes_A C_2/I(C_1\otimes_A C_2).$$
Question: "I am trying to solve an exercise from Vakil's lecture notes on algebraic geometry, namely, I want to show that
$\require{AMScd}$
\begin{CD}
X_1\times_Y X_2 @>>> X_1\times_Z X_2\\
@V V V @VV V\\
Y @>>> Y \times_Z Y
\end{CD}
is a cartesian diagram."
Answer: It seems to me that $F \circ F'=F' \circ F=Id$ is the identity. Hence there is a canonical isomorphism of commutative unital rings
$$B\otimes_{B\otimes_A B}(C_1\otimes_A C_2) \cong C_1\otimes_B C_2.$$
If we let $Y:=Spec(B), Z:=Spec(A), X_i:=Spec(C_i)$ we get a canonical isomorphism
$$Y\times_{Y\times_Z Y}(X_1\times_Z X_2)\cong X_1\times_Y X_2.$$
All maps are "canonical" and using a glueing lemma the theorem should follow.
Here are links to "category theoretic proofs":
The "magic diagram" is cartesian
Demystifying the Magic Diagram