Codimension of non-flat locus Let $X$, $Y$ be integral separated schemes of finite type over $\mathbb{C}$, $Y$ be normal, $f:X\rightarrow Y$ be a surjective morphism of schemes. Can the non-flat locus of $f$ be non-empty and have codimension $\geq 2$ in $X$? 
 A: Let $Y$ be a cone over a smooth projective variety which is a product and projectively normal (so $Y$ is normal). For example let $Y$ be the cone over $\mathbb P^1\times \mathbb P^1\subseteq \mathbb P^3$. In general, say $Y$ is a cone over $V\times W$.
Next let $H\subseteq W$ be an effective Cartier divisor (In the $\mathbb P^1\times \mathbb P^1$ example, $H$ is simply a point) and let $H'=V\times H$. Finally, let
$f:X\to Y$ be the blow up of $Y$ along its subscheme $Z$ which is the cone over $H'$. Then $f$ is an isomorphism (and hence flat) outside $Z$. Since $Z$ is a Weil divisor, which is Cartier except at the vertex, $f$ is a small morphism, so it is an isom outside a codimension $2$ subset. 
Addendum:
Here is an example with $Y$ smooth. Start with the above example with $V=\mathbb P^1$ and $W=\mathbb P^n$ with $n>1$ and $V\times W$ embedded with the Segre embedding. Construct the same (and for the sake of avoiding confusion, let's denote it differently) $f_0:X_0\to Y_0$ and let $v\in Y_0$ denote the vertex of the cone. Then a relatively simple computation shows that then $f^{-1}(v)\simeq V=\mathbb P^1$ (for the actual computation see Prop 3.3 of this paper. Note that this means that the exceptional set of $f$ is $1$-dimensional. Another simple calculation shows that $X_0$ is smooth (this is where the choice of $V$, $W$ and the embedding matters). 
Now let $f:X\colon =X_0\times _{Y_0}X_0\to Y\colon=X_0$. Then $f:X\to Y$ is birational (because of the dimensions there is only one component) and it's exceptional set (on $X$) is $2$-dimensional. From the construction and by the assumption that $n>1$ we obtain that $\dim X=\dim X_0= n+2>3$. Hence $f$ is an isomorphism (in particular, flat) outside a codimension $2$ subset of $X$ (but it is obviously not flat along the exceptional set).
A: Let $n \ge 2$, $X = \mathbb{A}^n$, $Y = \mathbb{A}^n/\{\pm 1\}$ and $f \colon X \to Y$ the quotient morphism. The non-flat locus of $f$ is the point $f(0) \in Y$.
A: Yes. Let $Y$ be $\mathrm{Spec} \ k[w,x,y,z]/(wz-xy)$. Let $X$ be $\mathrm{Proj} \ k[w,x,y,z, s,t]/(wz-xy,\ wt-xs,\ yt-zs)$ where $w$, $x$, $y$ and $z$ are in degree $0$ and $s$ and $t$ are in degree $1$. Then $Y$ is three dimensional with a singularity at $w=x=y=z=0$. The map $X \to Y$ is a resolution of this singularity; it is an ismorphism (and hence flat) away from the singularity and the fiber over the singularity is $\mathbb{P}^1$, so the nonflat locus is $1$-dimensional inside the $3$-fold $X$. 
This is a special case Sándor Kovács example, namely, it is what happens when you blow up the cone on $\mathbb{P}^1 \times (\mathrm{point})$ inside the cone on $\mathbb{P}^1 \times \mathbb{P}^1$.
A: Try $Y=\mathrm{Spec}\,\mathbb{C}[x^4, x^3y, xy^3, y^4]$ and $X$ its normalization.
