This cartesian square is important for establishing some basic results about base change in algebraic geometry (although, of course, it holds in every category). The maps are constructed as follows: $X_1 \times_Y X_2 \to X_1 \times_Z X_2$ corresponds to a pair of maps $X_1 \times_Y X_2 \to X_i$ whose composition to $Z$ is the same; well just take the projections from the fiber product and remark that since their composition to $Y$ is the same, the same is true for $Z$. The map $X_1 \times_Z X_2 \to Y \times_Z Y$ is induced by the two maps $X_i \to Z$. The map $Y \to Y \times_Z Y$ is the diagonal map, which is defined to correspond to the identity of $Y$ in both factors. Finally, the morphism $X_1 \times_Y X_2 \to Y$ is just the natural map. So to sum up: Every morphism in the diagram is defined canonically. Of course there are other choices possible, but no other choice does make sense.
I would like to make a digression which makes this cartesian square even more clear and deduces it from a more general result, namely that limits commute with limits. Besides, the general result will also yield other canonical isomorphisms which occur often in algebraic geometry. Typically, these isomorphisms are proven separatedly, but as you will see, they are all just corollaries of the following:
Lemma. In an arbitrary category, consider the following commutative diagram:
$$
\require{AMScd}
\begin{CD}
X_1 @>>> X_0 @<<< X_2\\
@VVV @VVV @VVV\\
S_1 @>>> S_0 @<<< S_2\\
@AAA @AAA @AAA\\
Y_1 @>>> Y_0 @<<< Y_2
\end{CD}
$$
Assuming that all the fiber products exist, then we have
$$(X_1 \times_{S_1} Y_1) \times_{X_0 \times_{S_0} Y_0} (X_2 \times_{S_2} Y_2) = (X_1 \times_{X_0} X_2) \times_{S_1 \times_{S_0} S_2} (Y_1 \times_{Y_0} Y_2).$$
In order to make sense of the fiber products, we use, of course, the only possible maps. For example, the two squares on the left yield the map $X_1 \times_{S_1} Y_1 \to X_0 \times_{S_0} Y_0$. The Lemma may be memorized as follows: The horizontal fiber product of the vertical fiber products equals the vertical fiber product of the horizontal fiber products.
Now as for the proof of the Lemma, just use the Yoneda Lemma to reduce it to the case of the category of sets, where you can really see this equation immediately. It isn't necessary to draw any arrows and verify the universal property by hand; or rather you encode these arrows as elements.
The first corollary of the lemma is the "cancelling law":
For morphisms $X \to T \to S$ and $Y \to S$, we have $X \times_T (T \times_S Y) \cong X \times_S Y$.
Proof: Apply the lemma to:
$$
\require{AMScd}
\begin{CD}
X @>>> T @<<< T\\
@VVV @VVV @VVV\\
S @>>> S @<<< S\\
@AAA @AAA @AAA\\
S @>>> S @<<< Y
\end{CD}
$$
The second one is the "Magic square" of the initial question:
For morphisms $X \to S$, $Y \to S$, $S \to T$, there is a cartesian square
$$
\require{AMScd}
\begin{CD}
X \times_S Y @>>> X \times_T Y \\
@VVV @VVV\\
S @>>> S \times_T S
\end{CD}
$$
Proof: Apply the lemma to:
$$
\require{AMScd}
\begin{CD}
S @>>> S @<<< X\\
@VVV @VVV @VVV\\
S @>>> T @<<< T\\
@AAA @AAA @AAA\\
S @>>> S @<<< Y
\end{CD}
$$