hcju/stacksqa huggingface dataset:
Assumptions (1) and (2) imply that $S' \to S$ is a universal homeomorphism (for example because $S_{red} = S'_{red}$ and using Lemma \ref{lemma-reduction-universal-homeomorphism}). Hence (3) implies that $X \to S$ is homeomorphism onto a closed subset of $S$. Then $X \to S$ is affine by Lemma \ref{lemma-homeomorphism-affine}. Let $U \subset S$ be an affine open, say $U = \Spec(A)$. Then $S' = \Spec(A/I)$ by (1) for a locally nilpotent ideal $I$ by (2). As $f$ is affine we see that $f^{-1}(U) = \Spec(B)$. Assumption (4) tells us $B$ is a finite type $A$-algebra (Lemma \ref{lemma-locally-finite-type-characterize}) or that $I$ is finitely generated (Lemma \ref{lemma-closed-immersion-finite-presentation}). Assumption (3) is that $A/I \to B/IB$ is surjective. From Algebra, Lemma \ref{algebra-lemma-surjective-mod-locally-nilpotent} if $A \to B$ is of finite type or Algebra, Lemma \ref{algebra-lemma-NAK} if $I$ is finitely generated and hence nilpotent we deduce that $A \to B$ is surjective. This means that $f$ is a closed immersion, see Lemma \ref{lemma-closed-immersion}.
If $f$ is universally closed, then $B$ is integral over $A$ by Lemma \ref{lemma-integral-universally-closed}. Hence $B'$ is integral over $A$ and $f'$ is universally closed (by the same lemma). This proves the case where $f$ is universally closed. \medskip\noindent Continuing, we see that $B$ is integral over $B'$  (Algebra, Lemma \ref{algebra-lemma-integral-permanence}) which implies $\Spec(B) \to \Spec(B')$ is surjective (Algebra, Lemma \ref{algebra-lemma-integral-overring-surjective}). Thus if $A \to B$ induces purely inseparable extensions of residue fields, then the same is true for $A \to B'$. This proves the case where $f$ is universally closed and universally injective, see Lemma \ref{lemma-universally-injective}. \medskip\noindent The case where $f$ is a universal homeomorphism follows from the remarks above, Lemma \ref{lemma-universal-homeomorphism}, and the obvious observation that if $f$ is surjective, then so is $f'$. \medskip\noindent If $A \to B$ induces isomorphisms on residue fields, then so does $A \to B'$ (see argument in second paragraph). In this way we see that the lemma holds in the remaining case.
If $f_\lambda$ is universally closed, then $B_\lambda$ is integral over $A$ by Lemma \ref{lemma-integral-universally-closed}. Hence $B$ is integral over $A$ and $f$ is universally closed (by the same lemma). This proves the case where each $f_\lambda$ is universally closed. \medskip\noindent For a prime $\mathfrak q \subset B$ lying over $\mathfrak p \subset A$ denote $\mathfrak q_\lambda \subset B_\lambda$ the inverse image. Then $\kappa(\mathfrak q) = \colim \kappa(\mathfrak q_\lambda)$. Thus if $A \to B_\lambda$ induces purely inseparable extensions of residue fields, then the same is true for $A \to B$. This proves the case where $f_\lambda$ is universally closed and universally injective, see Lemma \ref{lemma-universally-injective}. \medskip\noindent The case where $f$ is a universal homeomorphism follows from the remarks above and Lemma \ref{lemma-universal-homeomorphism} combined with the fact that prime ideals in $B$ are the same thing as compatible sequences of prime ideals in all of the $B_\lambda$. \medskip\noindent If $A \to B_\lambda$ induces isomorphisms on residue fields, then so does $A \to B$ (see argument in second paragraph). In this way we see that the lemma holds in the remaining case.
Recall that $A \subset B$ is integral (Lemma \ref{lemma-integral-universally-closed}). By Lemma \ref{lemma-subalgebra-inherits} we may assume that $B$ is generated by a single element over $A$. Hence $B$ is finite over $A$ (Algebra, Lemma \ref{algebra-lemma-characterize-finite-in-terms-of-integral}). Hence the support of $B/A$ as an $A$-module is closed and not empty (Algebra, Lemmas \ref{algebra-lemma-support-closed} and \ref{algebra-lemma-support-zero}). Let $\mathfrak p \subset A$ be a minimal prime of the support. After replacing $A \subset B$ by $A_\mathfrak p \subset B_\mathfrak p$ (permissible by Lemma \ref{lemma-special-elements-and-localization}) we may assume that $(A, \mathfrak m)$ is a local ring, that $B$ is finite over $A$, and that $B/A$ has support $\{\mathfrak m\}$ as an $A$-module. Since $B/A$ is a finite module, we see that $I = \text{Ann}_A(B/A)$ satisfies $\mathfrak m = \sqrt{I}$ (Algebra, Lemma \ref{algebra-lemma-support-closed}). Let $\mathfrak m' \subset B$ be the unique prime ideal lying over $\mathfrak m$. Because $\Spec(B) \to \Spec(A)$ is a homeomorphism, we find that $\mathfrak m' = \sqrt{IB}$. For $f \in \mathfrak m'$ pick $n \geq 1$ such that $f^n \in IB$. Then also $f^{n + 1} \in IB$. Since $IB \subset A$ by our choice of $I$ we conclude that $f^n, f^{n + 1} \in A$. Using Lemma \ref{lemma-nth-and-nplusone-implies-square-and-cube} we conclude our lemma is true if $\mathfrak m' \not \subset A$. However, if $\mathfrak m' \subset A$, then $\mathfrak m' = \mathfrak m$ and we conclude that $A = B$ as the residue fields are isomorphic as well by assumption. This contradiction finishes the proof.
The argument is almost exactly the same as in the proof of Lemma \ref{lemma-square-and-cube} but we write everything out to make sure it works. \medskip\noindent Recall that $A \subset B$ is integral (Lemma \ref{lemma-integral-universally-closed}). By Lemma \ref{lemma-subalgebra-inherits} we may assume that $B$ is generated by a single element over $A$. Hence $B$ is finite over $A$ (Algebra, Lemma \ref{algebra-lemma-characterize-finite-in-terms-of-integral}). Hence the support of $B/A$ as an $A$-module is closed and not empty (Algebra, Lemmas \ref{algebra-lemma-support-closed} and \ref{algebra-lemma-support-zero}). Let $\mathfrak p \subset A$ be a minimal prime of the support. After replacing $A \subset B$ by $A_\mathfrak p \subset B_\mathfrak p$ (permissible by Lemma \ref{lemma-special-elements-and-localization}) we may assume that $(A, \mathfrak m)$ is a local ring, that $B$ is finite over $A$, and that $B/A$ has support $\{\mathfrak m\}$ as an $A$-module. Since $B/A$ is a finite module, we see that $I = \text{Ann}_A(B/A)$ satisfies $\mathfrak m = \sqrt{I}$ (Algebra, Lemma \ref{algebra-lemma-support-closed}). Let $\mathfrak m' \subset B$ be the unique prime ideal lying over $\mathfrak m$. Because $\Spec(B) \to \Spec(A)$ is a homeomorphism, we find that $\mathfrak m' = \sqrt{IB}$. For $f \in \mathfrak m'$ pick $n \geq 1$ such that $f^n \in IB$. Then also $f^{n + 1} \in IB$. Since $IB \subset A$ by our choice of $I$ we conclude that $f^n, f^{n + 1} \in A$. Using Lemma \ref{lemma-nth-and-nplusone-implies-square-and-cube} we conclude our lemma is true if $\mathfrak m' \not \subset A$. If $\mathfrak m' \subset A$, then $\mathfrak m' = \mathfrak m$. Since $A \not = B$ we conclude the map $\kappa = A/\mathfrak m \to B/\mathfrak m' = \kappa'$ of residue fields cannot be an isomorphism. By Lemma \ref{lemma-universally-injective} we conclude that the characteristic of $\kappa$ is a prime number $p$ and that the extension $\kappa'/\kappa$ is purely inseparable. Pick $b \in B$ whose image in $\kappa'$ is an element not contained in $\kappa$ but whose $p$th power is in $\kappa$. Then $b \not \in A$, $b^p \in A$, and $pb \in A$ (because $pb \in \mathfrak m' = \mathfrak m \subset A$) as desired.
If (2) holds, then (1) holds by Algebra, Lemma \ref{algebra-lemma-p-ring-map}. Assume (1). Then the kernel of $A \to B$ consists of nilpotent elements by Algebra, Lemma \ref{algebra-lemma-image-dense-generic-points}. Thus we may replace $A$ by the image of $A \to B$ and assume that $A \subset B$. By Algebra, Lemma \ref{algebra-lemma-help-with-powers} the set $$ B' = \{b \in B \mid p^nb, b^{p^n} \in A\text{ for some }n \geq 0\} $$ is an $A$-subalgebra of $B$ (being closed under products is trivial). We have to show $B' = B$. If not, then according to Lemma \ref{lemma-pth-power-and-multiple} there exists a $b \in B$, $b \not \in B'$ with either $b^2, b^3 \in B'$ or there exists a prime number $\ell$ with $\ell b, b^\ell \in B'$. We will show both cases lead to a contradiction, thereby proving the lemma. \medskip\noindent Since $A[1/p] = B[1/p]$ we can choose a $p$-power $q$ such that $qb \in A$. \medskip\noindent If $b^2, b^3 \in B'$ then also $b^q \in B'$. By definition of $B'$ we find that $(b^q)^{q'} \in A$ for some $p$-power $q'$. Then $qq'b, b^{qq'} \in A$ whence $b \in B'$ which is a contradiction. \medskip\noindent Assume now there exists a prime number $\ell$ with $\ell b, b^\ell \in B'$. If $\ell \not = p$ then $\ell b \in B'$ and $qb \in A \subset B'$ imply $b \in B'$ a contradiction. Thus $\ell = p$ and $b^p \in B'$ and we get a contradiction exactly as before.
We will use the criterion of Lemma \ref{lemma-universal-homeomorphism} to check this. In both cases the ring map is integral. Thus it suffices to show that given a field $k$ and a ring map $\varphi : A \to k$ the $k$-algebra $B \otimes_A k$ has a unique prime ideal whose residue field is equal to $k$ in case (1) and purely inseparable over $k$ in case (2). See Lemma \ref{lemma-universally-injective}. \medskip\noindent In case (1) set $\lambda = 0$ if $\varphi(x) = 0$ and set $\lambda = \varphi(y)/\varphi(x)$ if not. Then $B = k[t]/(t^2 - \lambda^2, t^3 - \lambda^2)$. Thus the result is clear. \medskip\noindent In case (2) if the characteristic of $k$ is $p$, then we obtain $\varphi(y) = 0$ and $B = k[t]/(t^p - \varphi(x))$ which is a local Artinian $k$-algebra whose residue field is either $k$ or a degree $p$ purely inseparable extension of $k$. If the characteristic of $k$ is not $p$, then setting $\lambda = \varphi(y)/p$ we see $B = k[t]/(t - \lambda) = k$ and we conclude as well.
Proof of (1). We will use the criterion of Algebra, Lemma \ref{algebra-lemma-when-colimit}. Let $A \to C$ be of finite presentation and let $\varphi : C \to B$ be an $A$-algebra map. Let $B' = \varphi(C) \subset B$ be the image. Then $A \to B'$ induces a universal homeomorphism on spectra by Lemma \ref{lemma-subalgebra-inherits}. By Algebra, Lemma \ref{algebra-lemma-ring-colimit-fp} we can write $B' = \colim_{i \in I} B_i$ with $A \to B_i$ of finite presentation and surjective transition maps. By Algebra, Lemma \ref{algebra-lemma-characterize-finite-presentation} we can choose an index $0 \in I$ and a factorization $C \to B_0 \to B'$ of the map $C \to B'$. We claim that $\Spec(B_i) \to \Spec(A)$ is a universal homeomorphism for $i$ sufficiently large. The claim finishes the proof of (1). \medskip\noindent Proof of the claim. By Lemma \ref{lemma-reduction-universal-homeomorphism} the ring map $A_{red} \to B'_{red}$ induces a universal homeomorphism on spectra. Thus $A_{red} \subset B'_{red}$ by Algebra, Lemma \ref{algebra-lemma-image-dense-generic-points}. Setting $A' = \Im(A \to B')$ we have surjections $A \to A' \to A_{red}$ inducing bijections $\Spec(A_{red}) = \Spec(A') = \Spec(A)$. Thus $A' \subset B'$ induces a universal homeomorphism on spectra. By Proposition \ref{proposition-universal-homeomorphism} and the fact that $B'$ is finite type over $A'$ we can find $n$ and $b'_1, \ldots, b'_n \in B'$ such that $B' = A'[b'_1, \ldots, b'_n]$ and such that for $j = 1, \ldots, n$ we have \begin{enumerate} \item $(b'_j)^2, (b'_j)^3 \in A'[b'_1, \ldots, b'_{j - 1}]$, or \item there exists a prime number $p$ with $pb'_j, (b'_j)^p \in A'[b'_1, \ldots, b'_{j - 1}]$. \end{enumerate} Choose $b_1, \ldots, b_n \in B_0$ lifting $b'_1, \ldots, b'_n$. For $i \geq 0$ denote $b_{j, i}$ the image of $b_j$ in $B_i$. For large enough $i$ we will have for $j = 1, \ldots, n$ \begin{enumerate} \item $b_{j, i}^2, b_{j, i}^3 \in A_i[b_{1, i}, \ldots, b_{j - 1, i}]$, or \item there exists a prime number $p$ with $pb_{j, i}, b_{j, i}^p \in A_i[b_{1, i}, \ldots, b_{j - 1, i}]$. \end{enumerate} Here $A_i \subset B_i$ is the image of $A \to B_i$. Observe that $A \to A_i$ is a surjective ring map whose kernel is a locally nilpotent ideal. After increasing $i$ more if necessary, we may assume $B_i$ is generated by $b_1, \ldots, b_n$ over $A_i$, in other words $B_i = A_i[b_1, \ldots, b_n]$. By Algebra, Lemmas \ref{algebra-lemma-p-ring-map} and \ref{algebra-lemma-2-3-ring-map} we conclude that $A \to A_i \to A_i[b_1] \to \ldots \to A_i[b_1, \ldots, b_n] = B_i$ induce universal homeomorphisms on spectra. This finishes the proof of the claim. \medskip\noindent The proof of (2) is exactly the same.
Suppose that $A$ is seminormal and $f \in A$. Let $x', y' \in A_f$ with $(x')^3 = (y')^2$. Write $x' = x/f^{2n}$ and $y' = y/f^{3n}$ for some $n \geq 0$ and $x, y \in A$. After replacing $x, y$ by $f^{2m}x, f^{3m}y$ and $n$ by $n + m$, we see that $x^3 = y^2$ in $A$. Then we find a unique $a \in A$ with $x = a^2$ and $y = a^3$. Setting $a' = a/f^n$ we get $x' = (a')^2$ and $y' = (a')^3$ as desired. Uniqueness of $a'$ follows from uniqueness of $a$. In exactly the same manner the reader shows that if $A$ is absolutely weakly normal, then $A_f$ is absolutely weakly normal. \medskip\noindent Assume $A$ is a ring and $f_1, \ldots, f_n \in A$ generate the unit ideal. Assume $A_{f_i}$ is seminormal for each $i$. Let $x, y \in A$ with $x^3 = y^2$. For each $i$ we find a unique $a_i \in A_{f_i}$ with $x = a_i^2$ and $y = a_i^3$ in $A_{f_i}$. By the uniqueness and the result of the first paragraph (which tells us that $A_{f_if_j}$ is seminormal) we see that $a_i$ and $a_j$ map to the same element of $A_{f_if_j}$. By Algebra, Lemma \ref{algebra-lemma-standard-covering} we find a unique $a \in A$ mapping to $a_i$ in $A_{f_i}$ for all $i$. Then $x = a^2$ and $y = a^3$ by the same token. Clearly this $a$ is unique. Thus $A$ is seminormal. If we assume $A_{f_i}$ is absolutely weakly normal, then the exact same argument shows that $A$ is absolutely weakly normal.
We will prove (3) and (4) and omit the proof of (1) and (2). Let $h : X' \to X$ be a morphism of schemes. If (3) holds for $X$ and $X'$, then $X' \times_X X^{sn} \to X'$ is a universal homeomorphism and hence we get a unique morphism $(X')^{sn} \to X' \times_X X^{sn}$ over $X'$ by the universal property of $(X')^{sn} \to X'$. Composed with the projection $X' \times_X X^{sn} \to X^{sn}$ we obtain $h^{sn}$. If in addition (4) holds for $X$ and $X'$ and $h$ is an open immersion, then $X' \times_X X^{sn}$ is seminormal (Lemma \ref{lemma-locally-seminormal}) and we deduce that $(X')^{sn} \to X' \times_X X^{sn}$ is an isomorphism. \medskip\noindent Recall that any universal homeomorphism is affine, see Lemma \ref{lemma-homeomorphism-affine}. Thus if $X$ is affine then (3) and (4) follow immediately from Lemma \ref{lemma-seminormalization-ring}. Let $X$ be a scheme and let $\mathcal{B}$ be the set of affine opens of $X$. For each $U \in \mathcal{B}$ we obtain $U^{sn} \to U$ and for $V \subset U$, $V, U \in \mathcal{B}$ we obtain a canonical isomorphism $\rho_{V, U} : V^{sn} \to V \times_U U^{sn}$ by the discussion in the previous paragraph. Thus by relative glueing (Constructions, Lemma \ref{constructions-lemma-relative-glueing}) we obtain a morphism $X^{sn} \to X$ which restricts to $U^{sn}$ over $U$ compatibly with the $\rho_{V, U}$. Next, let $Y \to X$ be a universal homeomorphism. Then $U \times_X Y \to U$ is a universal homeomorphism for $U \in \mathcal{B}$ and we obtain a unique morphism $g_U : U^{sn} \to U \times_X Y$ over $U$. These $g_U$ are compatible with the morphisms $\rho_{V, U}$; details omitted. Hence there is a unique morphism $g : X^{sn} \to Y$ over $X$ agreeing with $g_U$ over $U$, see Constructions, Remark \ref{constructions-remark-relative-glueing-functorial}. This proves (3) for $X$. The proof of (4) is similar; details omitted.
Let $V \subset S$ be affine open. In all three cases the morphism is affine hence $f^{-1}(V)$ is affine. Thus we may write $V = \Spec(R)$ and $f^{-1}(V) = \Spec(A)$ for some $R$-algebra $A$. Assume (1). This means we can cover $S$ by affine opens $V = \Spec(R)$ such that $A$ is finite free as an $R$-module. Then $R \to A$ is of finite presentation by Algebra, Lemma \ref{algebra-lemma-finite-finite-type}. Thus (2) holds. Conversely, assume (2). For every affine open $V = \Spec(R)$ of $S$ the ring map $R \to A$ is finite and of finite presentation and $A$ is flat as an $R$-module. By Algebra, Lemma \ref{algebra-lemma-finite-finitely-presented-extension} we see that $A$ is finitely presented as an $R$-module. Thus Algebra, Lemma \ref{algebra-lemma-finite-projective} implies $A$ is finite locally free. Thus (1) holds. The Noetherian case follows as a finite module over a Noetherian ring is a finitely presented module, see Algebra, Lemma \ref{algebra-lemma-Noetherian-finite-type-is-finite-presentation}.
Write $X = \Spec(A)$ and $Y = \Spec(B)$. See also More on Algebra, Section \ref{more-algebra-section-descent-flatness-integral}. Let $x_1, \ldots, x_n \in B$ be generators of $B$ over $A$. For each $i$ we can choose a monic polynomial $P_i(T) \in A[T]$ such that $P(x_i) = 0$ in $B$. By Algebra, Lemma \ref{algebra-lemma-adjoin-roots} (applied $n$ times) there exists a finite locally free ring extension $A \subset A'$ such that each $P_i$ splits completely: $$ P_i(T) = \prod\nolimits_{k = 1, \ldots, d_i} (T - \alpha_{ik}) $$ for certain $\alpha_{ik} \in A'$. Set $$ C = A'[T_1, \ldots, T_n]/(P_1(T_1), \ldots, P_n(T_n)) $$ and $B' = A' \otimes_A B$. The map $C \to B'$, $T_i \mapsto 1 \otimes x_i$ is an $A'$-algebra surjection. Setting $X' = \Spec(A')$, $Y' = \Spec(B')$ and $Z' = \Spec(C)$ we see that (1) -- (4) hold. Part (5) holds because set theoretically $\Spec(C)$ is the union of the closed subschemes cut out by the ideals $$ (T_1 - \alpha_{1k_1}, T_2 - \alpha_{2k_2}, \ldots, T_n - \alpha_{nk_n}) $$ for any $1 \leq k_i \leq d_i$.
By Lemma \ref{lemma-finite-proper} we know that $f(T) \subset X$ is closed. Let $X = \bigcup X_i$ be an affine covering. Since $T$ is nowhere dense in $Y$, we see that also $T \cap f^{-1}(X_i)$ is nowhere dense in $f^{-1}(X_i)$. Hence if we can prove the theorem in the affine case, then we see that $f(T) \cap X_i$ is nowhere dense. This then implies that $T$ is nowhere dense in $X$ by Topology, Lemma \ref{topology-lemma-nowhere-dense-local}. \medskip\noindent Assume $X$ is affine. Choose a diagram $$ \xymatrix{ Z' \ar[rd] & Y' \ar[l]^i \ar[d]^{f'} \ar[r]_a & Y \ar[d]^f \\  & X' \ar[r]^b & X } $$ as in Lemma \ref{lemma-massage-finite}. The morphisms $a$, $b$ are open since they are finite locally free (Lemmas \ref{lemma-finite-flat} and \ref{lemma-fppf-open}). Hence $T' = a^{-1}(T)$ is nowhere dense, see Topology, Lemma \ref{topology-lemma-open-inverse-image-closed-nowhere-dense}. The morphism $b$ is surjective and open. Hence, if we can prove $f'(T') = b^{-1}(f(T))$ is nowhere dense, then $f(T)$ is nowhere dense, see Topology, Lemma \ref{topology-lemma-open-inverse-image-closed-nowhere-dense}. As $i$ is a closed immersion, by Topology, Lemma \ref{topology-lemma-closed-image-nowhere-dense} we see that $i(T') \subset Z'$ is closed and nowhere dense. Thus we have reduced the problem to the case discussed in the following paragraph. \medskip\noindent Assume that $Y = \bigcup_{i = 1, \ldots, n} Y_i$ is a finite union of closed subsets, each mapping isomorphically to $X$. Consider $T_i = Y_i \cap T$. If each of the $T_i$ is nowhere dense in $Y_i$, then each $f(T_i)$ is nowhere dense in $X$ as $Y_i \to X$ is an isomorphism. Hence $f(T) = f(T_i)$ is a finite union of nowhere dense closed subsets of $X$ and we win, see Topology, Lemma \ref{topology-lemma-nowhere-dense}. Suppose not, say $T_1$ contains a nonempty open $V \subset Y_1$. We are going to show this leads to a contradiction. Consider $Y_2 \cap V \subset V$. This is either a proper closed subset, or equal to $V$. In the first case we replace $V$ by $V \setminus V \cap Y_2$, so $V \subset T_1$ is open in $Y_1$ and does not meet $Y_2$. In the second case we have $V \subset Y_1 \cap Y_2$ is open in both $Y_1$ and $Y_2$. Repeat sequentially with $i = 3, \ldots, n$. The result is a disjoint union decomposition $$ \{1, \ldots, n\} = I_1 \amalg I_2, \quad 1 \in I_1 $$ and an open $V$ of $Y_1$ contained in $T_1$ such that $V \subset Y_i$ for $i \in I_1$ and $V \cap Y_i = \emptyset$ for $i \in I_2$. Set $U = f(V)$. This is an open of $X$ since $f|_{Y_1} : Y_1 \to X$ is an isomorphism. Then $$ f^{-1}(U) = V\ \amalg\ \bigcup\nolimits_{i \in I_2} (Y_i \cap f^{-1}(U)) $$ As $\bigcup_{i \in I_2} Y_i$ is closed, this implies that $V \subset f^{-1}(U)$ is open, hence $V \subset Y$ is open. This contradicts the assumption that $T$ is nowhere dense in $Y$, as desired.
Observe that any dense open of $X$ contains the points $x_i$ so the construction makes sense. To prove (1) or (2) we may replace $X$ by any dense open. Thus if $Z_1, \ldots, Z_n$ are the irreducible components of $X$, then we may replace $X$ by $X \setminus \bigcup_{i \not = j} Z_i \cap Z_j$. After doing this $X$ is the disjoint union of its irreducible components (viewed as open and closed subschemes). Then both the right hand side and the left hand side of the arrow are products over the irreducible components and we reduce to the case where $X$ is irreducible. \medskip\noindent Assume $X$ is irreducible with generic point $x$ lying over $s \in S$. Part (1) follows from part (1) of Lemma \ref{lemma-morphism-defined-local-ring}. Parts (2) and (3) follow from part (2) of the same lemma.
Let $U \subset X$ be an open dense subset. Then $U_i = (U \cap X_i) \setminus (\bigcup_{j \not = i} X_j)$ is nonempty open as it contained $\eta_i$, contained in $X_i$, and $\bigcup U_i \subset U \subset X$ is dense. Thus the identification in the lemma comes from the string of equalities \begin{align*} R(X) & = \colim_{U \subset X\text{ open dense}} \Mor(U, \mathbf{A}^1_\mathbf{Z}) \\ & = \colim_{U \subset X\text{ open dense}} \mathcal{O}_X(U) \\ & = \colim_{\eta_i \in U_i \subset X\text{ open}} \prod \mathcal{O}_X(U_i) \\ & = \prod \colim_{\eta_i \in U_i \subset X\text{ open}} \mathcal{O}_X(U_i) \\ & = \prod \mathcal{O}_{X, \eta_i} \end{align*} where the second equality is Schemes, Example \ref{schemes-example-global-sections}. The final statement follows from Algebra, Lemma \ref{algebra-lemma-minimal-prime-reduced-ring}.
First observe that under the assumption of $X$ being separated, there is a unique map of schemes $\Spec(\mathcal{O}_{X, \eta_2}) \to X$ over $X$ such that the composition $$ \Spec(R(X)) \longrightarrow \Spec(\mathcal{O}_{X, \eta_2}) \longrightarrow X $$ is the canonical map $\Spec(R(X)) \to X$. Namely, there is the canonical map $can : \Spec(\mathcal{O}_{X, \eta_2}) \to X$, see Schemes, Equation (\ref{schemes-equation-canonical-morphism}). Given a second morphism $a$ to $X$, we have that $a$ agrees with $can$ on the generic point of $\Spec(\mathcal{O}_{X, \eta_2})$ by assumption. Now $X$ being separated guarantees that the subset in $\Spec(\mathcal{O}_{X, \eta_2})$ where these two maps agree is closed, see Schemes, Lemma \ref{schemes-lemma-where-are-they-equal}. Hence $a = can$ on all of $\Spec(\mathcal{O}_{X, \eta_2})$. \medskip\noindent Assume $Z_1 \not \subset Z_2$ and assume on the contrary that $\mathcal{O}_{X, \eta_{1}} \subset \mathcal{O}_{X, \eta_{2}}$ as subrings of $R(X)$. Then we would obtain a second morphism $$ \Spec(\mathcal{O}_{X, \eta_{2}}) \longrightarrow \Spec(\mathcal{O}_{X, \eta_{1}}) \longrightarrow X. $$ By the above this composition would have to be equal to $can$. This implies that $\eta_2$ specializes to $\eta_1$ (see Schemes, Lemma \ref{schemes-lemma-specialize-points}). But this contradicts our assumption $Z_1 \not \subset Z_2$.
Let $(V, g)$ and $(V', g')$ be representatives of $\varphi$. Then $g, g'$ agree on a dense open subscheme $W \subset V \cap V'$. On the other hand, the equalizer $E$ of $g|_{V \cap V'}$ and $g'|_{V \cap V'}$ is a closed subscheme of $V \cap V'$ (Schemes, Lemma \ref{schemes-lemma-where-are-they-equal}). Now $W \subset E$ implies that $E = V \cap V'$ set theoretically. As $V \cap V'$ is reduced we conclude $E = V \cap V'$ scheme theoretically, i.e., $g|_{V \cap V'} = g'|_{V \cap V'}$. It follows that we can glue the representatives $g : V \to Y$ of $\varphi$ to a morphism $f : U \to Y$, see Schemes, Lemma \ref{schemes-lemma-glue}. We omit the proof of the final statement.