Let $X$, $Y$ be connected smooth schemes of finite type over an algebraically closed field of characteristic $0$. Let $f:X\rightarrow Y$ be a non-birational morphism surjective on the underlying topological spaces. Can the non-flat locus of $f$ be non-empty of codimension$\geq 2$ in $X$? For birational morphism, I belive ZMT plus [a purity theorem](https://stacks.math.columbia.edu/tag/0EA4) show that the answer is "no". 


P.S. This question was [posted](https://math.stackexchange.com/q/3182764/251240) on math.stackexchange 3 days ago but there was zero reaction so far.



Non-flat locus for smooth schemes
Suppose that $f \colon X \to Y$ is generically finite. Then the locus in $X$ where $f$ is not flat is the locus where the fiber is positive dimensional.


Now, let $Z$ be a projective threefold with a unique singular point $p \in Z$, admitting a small resolution $X \to Z$ (that is, a proper birational map that is an isomorphism outside of $p$, and such that the inverse image $E$ of $p$ is $1$-dimensional). Choose a finite map $Z \to \mathbb P^3$; then the composite $X\to \mathbb P^3$ is flat precisely outside of $E$.


