Is the restriction of a flat morphism flat? Let $X$ be a projective scheme, $X_1, X_2$ be closed subschemes of $X$. Let $f:X \to S$ be a flat morphism for some scheme $S$. Denote by $i_1$ and $i_2$ the natural inclusion maps from $X_1$ and $X_2$, respectively to $X$. Assume that the composition maps $f \circ i_1$ and $f \circ i_2$ are flat. Is it then true that the fiber product $X_1 \times_X X_2$ is flat over $S$ under the natural maps $f \circ i_1 \circ pr_1$ or $f \circ i_2 \circ pr_2$, where $pr_i$ is the natural projection morphism from $X_1 \times_X X_2$ onto its $i$-th coordinate?
 A: No, the fiber product is not always flat over $S$:   
Let $k$ be a field of characteristic $\neq 2$ and take  for $f$ the first projection $f:X=\mathbb A^2_k=\operatorname {Spec}k[x,y]\to S=\mathbb A^1_k=\operatorname {Spec} k[x]$, for $i_1$ the closed immersion of $X_1=V(x-y^2)$ into $X$ and for $i_2$ the closed immersion of $X_2=V(x+y^2)$ into $X$.
The fiber product $X=X_1\times_X X_2$ is then the same as the scheme theoretic intersection intersection $X_1\cap X_2=V((x-y^2,x+y^2))=V(x,y^2)$, a double point.
This fiber product is thus certainly not flat $(\bigstar) $ over $S=\mathbb A^1_k$, although $X,X_1$ and $X_2$ are $(\bigstar \bigstar)$.
$(\bigstar)$   Since it  corresponds to the ring morphism $k[x]\to k[x,y]/(x,y^2)=k[y]/(y^2):x\mapsto 0 $
$(\bigstar \bigstar) $ Recall that a morphism from an integral  reduced scheme to a nonsingular curve is flat iff it is dominant (Hartshorne, III 9.7, page 257), which shows that $X,X_1$ and $X_2$ are flat over $S$.
A: In the spirit of Georges's philosophy of recording useful (counter)examples, let me offer another:
Consider the projection $X = \mathbb A^2 \to S = \mathbb A^1$ given by $(x,y) \mapsto x$.
Now let $X_1$ be the line $y = 0$ and $X_2$ be the line $x  + y = 0$.  Both map
isomorphically to $\mathbb A^1$ (and an isomorphism is flat!).  However there
intersection is the single point $(0,0)$, which does not map flatly to $\mathbb A^1$.
(Note: as with Georges's answer, my varieties are not projective, because it is easier to write formulas in the affine setting.  It is an exercise to "complete" the above example to give an analogous example with projective varieties.)

General remark: As Georges pointed out in his answer, and as I used above,
the fibre product over $X$ of two closed subschemes of $X$ is just their (scheme-theoretic) intersection.  So the map you are asking about, namely $X_1\times_X X_2 \to S$, factors as the closed immersion $X_1\times X_2 \to X_1$, followed by the flat map $X_1 \to S$.  Since closed immersions are never flat unless they are isomorphisms, there is no reason at all to think that the answer to your question would be yes, and of course it was easy for Georges and me to come up with counterexamples, just by thinking of examples of non-trivial (and hence non-flat) closed immersions.
