Proof. Since $p$ is flat and finitely presented, the image of $p$ is open. Up to replacing $X$ by the open image of $p$, assume that $p$ is surjective. Edit. Also, since $X$ is quasi-compact, it has a finite cover by open affines, $X_\beta$. For every collection $i_\beta:Z_\beta \to Y\times_X X_\beta$ as in the proposition, for the disjoint union $Z=\sqcup_\beta Z_\beta$ and for the unique morphism $i:Z\to Y$ whose restriction to each $Z_\beta$ equals $i_\beta$, also $i:Z\to Y$ satisfies the conditions in the proposition. Thus, it suffices to prove the result when $X$ is affine.
The argument is essentially a Bertini hyperplane argument. First of all, up to replacing $Y$ by a disjoint union of open affine subschemes, assume that $Y$ is affine. Denote by $Y_{\text{equi}}\subset Y$ the maximal open subset on which $p$ is (locally) equidimensional, i.e., at every point of every fiber of $p$, the irreducible components of the fiber containing the point all have equal dimensions. The restriction Edit. This open subset contains the open complement $U$ of the closed union $C$ of the finitely many intersections $Y_i\cap Y_j$ of irreducible components $Y_i$ and $Y_j$ of $Y$ such that the (constant) relative dimensions of $Y_i$ and $Y_j$ over $X$ are not equal. For every point $x\in X$, there exists an irreducible component $Y_i$ such that the fiber $(Y_i)_x$ has maximal dimension. Since $p$ is flat, $U\cap (Y_i)_x$ is dense in $(Y_i)_x$: if $(Y_j)_x\cap (Y_i)_x$ is nonempty, and if $\text{dim}(Y_j)_x\neq\text{dim}(Y_i)_x$, then $(Y_j)_x$ has smaller relative dimension, so $(Y_i)_x\cap (Y_j)_x$ is nowhere dense in $(Y_i)_x$.
Thus, the restriction of $p$ to $Y_{\text{equi}}$ is still surjective. Thus, without loss of generality, assume that $p$ is (locally) equidimensional. Then on every connected component $Y_\alpha$ of $Y$, the fiber dimension of $p$ is constant. We construct $Z$ as a disjoint union of schemes $Z_\alpha$ where $i_\alpha:Z_\alpha\to Y_\alpha$ is a disjoint union of locally closed immersions such that $p_\alpha\circ i_\alpha$ is a quasi-finite, flat morphism with image equal to the image of $p_\alpha$.
Let $e:Y\hookrightarrow \mathbb{A}^n_X$ be a closed immersion of $X$-schemes. For every point in the image of $p$, $x:\text{Spec}\ k \to X,$ the fiber $Y_x=p^{-1}(x)$ has only finitely many associated points. For every linear polynomial
Edit. Since $t_x$ in the coordinate ring$Y_x$ has dimension $k[\mathbb{A}^n_k]=k[t_1,\dots,t_n]$$d>0$, there exist points $y\in Y$ that vanishes atspecialize to none of these finitely many associated points. By prime avoidance, multiplicationthere exists an element $t_x\in k[\mathbb{A}^n_k]=k[t_1,\dots,t_n]$ that is in the prime ideal of $y$ yet in none of the associated primes.
For every linear polynomial $t_x$ in the coordinate ring $k[\mathbb{A}^n_k]=k[t_1,\dots,t_n]$ that vanishes at none of these finitely many associated points, Multiplication by $t_x$ is injective on $\mathcal{O}_{Y_x}$. Let $t\in\mathcal{O}_{X,x}[t_1,\dots,t_n]$ be an element mapping to $t_x$. Denote by $H \subseteq \mathbb{A}^{n}_{\mathcal{O}_{X,x}}$ the zero scheme of $t$.