Let $X,Y$ be $S$-schemes and $S\to T$ a closed immersion of schemes. Prove that we have a natural $T$-isomorphism $X\times_S Y\simeq X\times_T Y$.
Let $f:X\to S$ and $g:Y\to S$ the structural morphisms and $h:S\to T$ the closed immersion. We immetiately that $X,Y$ are also $T$-schemes with structure morphisms $h\circ f,h\circ g$ respectively. Also $X\times_S Y$ has a $T$-scheme structure via $(x,y)\mapsto h\circ f(x)=h\circ g(y)$.
We have the natural $T$-morphisms $p_T:X\times_T Y\to X,q_T:X\times_T Y\to Y$ as well as $p_S:X\times_S Y\to X$ and $p_S:X\times_S Y\to X$ as well as $\pi:X\times_T Y\to T$ given by $(x,y)\mapsto h\circ f(x)=h\circ g(y)$.
By the universal property, we have a unique morphism $\varphi:X\times_S Y\to X\times_T Y$ with $p_T\circ \varphi=p_S$ and $q_T\circ \varphi=q_S$.
But I don't know how to prove $\varphi$ is an isomorphism.
Set theoretically, we see that $X\times_S Y=X\times_T Y$, since $f(x)=g(y)\Leftrightarrow h\circ f(x)=h\circ g(y)$ by injectivity of $h$, so it's natural to presume an ismorphism, but that's far from showing $\varphi$ is an isomorphism.
How do I do that?
I don't think one even needs that $h$ is a closed immersion - I believe this is true whenever $h$ is a monomorphism, and any closed immersion is a monomorphism. (See, e.g., here.)
The point is that when $h$ is a monomorphism, the fiber products $X \times_{S} Y$ and $X \times_{T} Y$ satisfy the same universal property. Given maps $u \colon Z \to X, v \colon Z \to Y$ such that the compositions $Z \to X \to S, Z \to Y \to S$ agree, then clearly, the compositions $Z \to X \to S \to T, Z \to Y \to S \to T$ agree. (As you've observed, this is what gives you the universal map $\varphi \colon X \times_{S} Y \to X \times_{T} Y$).
On the other hand, if $u, v$ are such that the compositions $Z \to X \to S \to T, Z \to Y \to S \to T$ agree, then $Z \to X \to S, Z \to Y \to S$ agree by cancellation. This gives you the universal map $X \times_{T} Y \to X \times_{S} Y$ which is inverse to your map $\varphi$.