hcju/stacksqa huggingface dataset:
According to Proposition \ref{proposition-when-gerbe} it is enough to find a dense open substack $\mathcal{U}$ such that $\mathcal{I}_\mathcal{U} \to \mathcal{U}$ is flat and locally of finite presentation. Note that $\mathcal{I}_\mathcal{U} = \mathcal{I}_\mathcal{X} \times_\mathcal{X} \mathcal{U}$, see Lemma \ref{lemma-cartesian-square-inertia}. \medskip\noindent Choose a presentation $\mathcal{X} = [U/R]$. Let $G \to U$ be the stabilizer group algebraic space of the groupoid $R$. By Lemma \ref{lemma-presentation-inertia} we see that $G \to U$ is the base change of $\mathcal{I}_\mathcal{X} \to \mathcal{X}$ hence quasi-compact (by assumption) and locally of finite type (by Lemma \ref{lemma-inertia}). Let $W \subset U$ be the largest open (possibly empty) subscheme such that the restriction $G_W \to W$ is flat and locally of finite presentation (we omit the proof that $W$ exists; hint: use that the properties are local). By Morphisms of Spaces, Proposition \ref{spaces-morphisms-proposition-generic-flatness-reduced} we see that $W \subset U$ is dense. Note that $W \subset U$ is $R$-invariant by More on Groupoids in Spaces, Lemma \ref{spaces-more-groupoids-lemma-property-G-invariant}. Hence $W$ corresponds to an open substack $\mathcal{U} \subset \mathcal{X}$ by Properties of Stacks, Lemma \ref{stacks-properties-lemma-substacks-presentation}. Since $|U| \to |\mathcal{X}|$ is open and $|W| \subset |U|$ is dense we conclude that $\mathcal{U}$ is dense in $\mathcal{X}$. Finally, the morphism $\mathcal{I}_\mathcal{U} \to \mathcal{U}$ is flat and locally of finite presentation because the base change by the surjective smooth morphism $W \to \mathcal{U}$ is the morphism $G_W \to W$ which is flat and locally of finite presentation by construction. See Lemmas \ref{lemma-descent-flat} and \ref{lemma-descent-finite-presentation}.
Let $f'$ be the homeomorphism between $X$ and $V$ induced by $f$. Then $f = j \circ f'$ as maps of topological spaces. Since there is an isomorphism of sheaves $f^\sharp : f^{-1}(\mathcal{O}_Y) \to \mathcal{O}_X$, there is an isomorphism of rings $f^\sharp : \Gamma(U, f^{-1}(\mathcal{O}_Y)) \to \Gamma(U, \mathcal{O}_X)$ for each open subset $U \subset X$. Since $\mathcal{O}_V = j^{-1}\mathcal{O}_Y$ and $f^{-1} = f'^{-1} j^{-1}$ (Sheaves, Lemma \ref{sheaves-lemma-pullback-composition}) we see that $f^{-1}\mathcal{O}_Y = f'^{-1}\mathcal{O}_V$, hence $\Gamma(U, f'^{-1}(\mathcal{O}_V)) \to \Gamma(U, f^{-1}(\mathcal{O}_Y))$ is an isomorphism for every $U \subset X$ open. By composing these we get an isomorphism of rings $$ \Gamma(U, f'^{-1}(\mathcal{O}_V)) \to \Gamma(U, \mathcal{O}_X) $$ for each open subset $U \subset X$, and therefore an isomorphism of sheaves $f^{-1}(\mathcal{O}_V) \to \mathcal{O}_X$. In other words, we have an isomorphism $f'^{\sharp} : f'^{-1}(\mathcal{O}_V) \to \mathcal{O}_X$ and therefore an isomorphism of locally ringed spaces $(f', f'^{\sharp}) : (X, \mathcal{O}_X) \to (V, \mathcal{O}_V)$ (use Lemma \ref{lemma-isomorphism-locally-ringed}). Note that $f = j \circ f'$ as morphisms of locally ringed spaces by construction. \medskip\noindent Suppose we have another morphism $f'' : (X, \mathcal{O}_X) \to (V, \mathcal{O}_Y)$ such that $f = j \circ f''$. At any point $x \in X$, we have $j(f'(x)) = j(f''(x))$ from which it follows that $f'(x) = f''(x)$ since $j$ is the inclusion map; therefore $f'$ and $f''$ are the same as morphisms of topological spaces. On structure sheaves, for each open subset $U \subset X$ we have a commutative diagram $$ \xymatrix @R=5em{ \Gamma(U, f^{-1}(\mathcal{O}_Y)) \ar[d]_\cong\ar[r]^\cong & \Gamma(U, \mathcal{O}_X) \\ \Gamma(U, f'^{-1}(\mathcal{O}_V)) \ar@/^/[ru]^{f'^\sharp} \ar@/_/[ru]_{f''^\sharp} & } $$ from which we see that $f'^\sharp$ and $f''^\sharp$ define the same morphism of sheaves.
Clearly if $f$ factors as $Y \to Z \to X$ then the map $f^*\mathcal{I} \to \mathcal{O}_Y$ is zero. Conversely suppose that $f^*\mathcal{I} \to \mathcal{O}_Y$ is zero. Pick any $y \in Y$, and consider the ring map $f^\sharp_y : \mathcal{O}_{X, f(y)} \to \mathcal{O}_{Y, y}$. Since the composition $\mathcal{I}_{f(y)} \to \mathcal{O}_{X, f(y)} \to \mathcal{O}_{Y, y}$ is zero by assumption and since $f^\sharp_y(1) = 1$ we see that $1 \not \in \mathcal{I}_{f(y)}$, i.e., $\mathcal{I}_{f(y)} \not = \mathcal{O}_{X, f(y)}$. We conclude that $f(Y) \subset Z = \text{Supp}(\mathcal{O}_X/\mathcal{I})$. Hence $f = i \circ g$ where $g : Y \to Z$ is continuous. Consider the map $f^\sharp : \mathcal{O}_X \to f_*\mathcal{O}_Y$. The assumption $f^*\mathcal{I} \to \mathcal{O}_Y$ is zero implies that the composition $\mathcal{I} \to \mathcal{O}_X \to f_*\mathcal{O}_Y$ is zero by adjointness of $f_*$ and $f^*$. In other words, we obtain a morphism of sheaves of rings $\overline{f^\sharp} : \mathcal{O}_X/\mathcal{I} \to f_*\mathcal{O}_Y$. Note that $f_*\mathcal{O}_Y = i_*g_*\mathcal{O}_Y$ and that $\mathcal{O}_X/\mathcal{I} = i_*\mathcal{O}_Z$. By Sheaves, Lemma \ref{sheaves-lemma-equivalence-categories-closed-structures} we obtain a unique morphism of sheaves of rings $g^\sharp : \mathcal{O}_Z \to g_*\mathcal{O}_Y$ whose pushforward under $i$ is $\overline{f^\sharp}$. We omit the verification that $(g, g^\sharp)$ defines a morphism of locally ringed spaces and that $f = i \circ g$ as a morphism of locally ringed spaces. The uniqueness of $(g, g^\sharp)$ was pointed out above.
Recall that $D(g) = \Spec(R_g)$ (see Algebra, Lemma \ref{algebra-lemma-standard-open}). Thus (a) holds because $f$ maps to an element of $R_g$ which is not contained in any prime ideal, and hence invertible, see Algebra, Lemma \ref{algebra-lemma-Zariski-topology}. Write the inverse of $f$ in $R_g$ as $a/g^d$. This means $g^d - af$ is annihilated by a power of $g$, whence (b). For (c), the map $R_f \to R_g$ exists by (a) from the universal property of localization, or we can define it by mapping $b/f^n$ to $a^nb/g^{ne}$. The equality $M_f = M \otimes_R R_f$ can be used to obtain the map on modules, or we can define $M_f \to M_g$ by mapping $x/f^n$ to $a^nx/g^{ne}$. \medskip\noindent Recall that $D(f)$ is quasi-compact, see Algebra, Lemma \ref{algebra-lemma-qc-open}. Hence the second statement follows directly from the fact that the standard opens form a basis for the topology. \medskip\noindent The third statement follows directly from Algebra, Lemma \ref{algebra-lemma-Zariski-topology}.
Consider the commutative diagram $$ \xymatrix{ \Gamma(X, \mathcal{O}_X) \ar[r] & \mathcal{O}_{X, x} \\ \Gamma(Y, \mathcal{O}_Y) \ar[r] \ar[u] & \mathcal{O}_{Y, f(x)} \ar[u] } $$ (see the discussion of $f$-maps below Sheaves, Definition \ref{sheaves-definition-f-map}). Since the right vertical arrow is local we see that $\mathfrak m_{f(x)}$ is the inverse image of $\mathfrak m_x$. The result follows.
This is a special case of Modules, Lemma \ref{modules-lemma-s-open}, but we also give a direct proof. Suppose that $U \subset X$ and $V \subset X$ are two open subsets such that $f|_U$ has an inverse $g$ and $f|_V$ has an inverse $h$. Then clearly $g|_{U\cap V} = h|_{U\cap V}$. Thus it suffices to show that $f$ is invertible in an open neighbourhood of any $x \in D(f)$. This is clear because $f \not \in \mathfrak m_x$ implies that $f \in \mathcal{O}_{X, x}$ has an inverse $g \in \mathcal{O}_{X, x}$ which means there is some open neighbourhood $x \in U \subset X$ so that $g \in \mathcal{O}_X(U)$ and $g\cdot f|_U = 1$.
We may assume that $Y = \Spec(R)$ and $f \in R$. Consider the morphism of affine schemes $\phi : U = \Spec(R_f) \to \Spec(R) = Y$ induced by the ring map $R \to R_f$. By Algebra, Lemma \ref{algebra-lemma-standard-open} we know that it is a homeomorphism onto $D(f)$. On the other hand, the map $\phi^{-1}\mathcal{O}_Y \to \mathcal{O}_U$ is an isomorphism on stalks, hence an isomorphism. Thus we see that $\phi$ is an open immersion. We conclude that $D(f)$ is isomorphic to $U$ by Lemma \ref{lemma-open-immersion}.
This is just an application of Lemma \ref{lemma-morphism-into-affine}. First of all, by that lemma, the affine scheme $\Spec(\mathbf{Z})$ is the final object in the category of locally ringed spaces. Thus the first displayed formula follows from the second. To prove the second note that for any locally ringed space $X$ we have \begin{eqnarray*} \Mor(X, \Spec(A \otimes_R B)) & = & \Hom(A \otimes_R B, \mathcal{O}_X(X)) \\ & = & \Hom(A, \mathcal{O}_X(X)) \times_{\Hom(R, \mathcal{O}_X(X))} \Hom(B, \mathcal{O}_X(X)) \\ & = & \Mor(X, \Spec(A)) \times_{\Mor(X, \Spec(R))} \Mor(X, \Spec(B)) \end{eqnarray*} which proves the formula. See Categories, Section \ref{categories-section-fibre-products} for the relevant definitions.
Set $R = \Gamma(X, \mathcal{O}_X)$. Note that $R = \mathcal{O}_X(U) \times \mathcal{O}_X(V)$ by the sheaf property. By Lemma \ref{lemma-morphism-into-affine} there is a canonical morphism of locally ringed spaces $X \to \Spec(R)$. By Algebra, Lemma \ref{algebra-lemma-spec-product} we see that as a topological space $\Spec(\mathcal{O}_X(U)) \amalg \Spec(\mathcal{O}_X(V)) = \Spec(R)$ with the maps coming from the ring homomorphisms $R \to \mathcal{O}_X(U)$ and $R \to \mathcal{O}_X(V)$. This of course means that $\Spec(R)$ is the coproduct in the category of locally ringed spaces as well. By assumption the morphism $X \to \Spec(R)$ induces an isomorphism of $\Spec(\mathcal{O}_X(U))$ with $U$ and similarly for $V$. Hence $X \to \Spec(R)$ is an isomorphism.
By Modules, Lemma \ref{modules-lemma-construct-quasi-coherent-sheaves} we have a morphism $\mathcal{F}_M \to \widetilde M$ corresponding to the map $M \to \Gamma(X, \widetilde M) = M$. Let $x \in X$ correspond to the prime $\mathfrak p \subset R$. The induced map on stalks are the maps $\mathcal{O}_{X, x} \otimes_R M \to M_{\mathfrak p}$ which are isomorphisms because $R_{\mathfrak p} \otimes_R M = M_{\mathfrak p}$. Hence the map $\mathcal{F}_M \to \widetilde M$ is an isomorphism. The mapping property follows from the mapping property of the sheaves $\mathcal{F}_M$.
[First proof] Using Lemma \ref{lemma-compare-constructions} and Modules, Lemma \ref{modules-lemma-construct-quasi-coherent-sheaves} we see that the functor $M \mapsto \widetilde M$ can be viewed as $\pi^*$ for a morphism $\pi$ of ringed spaces. And pulling back modules commutes with tensor constructions by Modules, Lemmas \ref{modules-lemma-tensor-product-pullback} and \ref{modules-lemma-pullback-tensor-algebra}. The morphism $\pi : (X, \mathcal{O}_X) \to (\{*\}, R)$ is flat for example because the stalks of $\mathcal{O}_X$ are localizations of $R$ (Lemma \ref{lemma-spec-sheaves}) and hence flat over $R$. Thus pullback by $\pi$ commutes with internal hom if the first module is finitely presented by Modules, Lemma \ref{modules-lemma-pullback-internal-hom}.
The first assertion follows from the identification in Lemma \ref{lemma-compare-constructions} and the result of Modules, Lemma \ref{modules-lemma-restrict-quasi-coherent}. The second assertion follows from the fact that $\psi^{-1}(D(f)) = D(\psi^\sharp(f))$ and hence $$ \psi_* \widetilde N(D(f)) = \widetilde N(D(\psi^\sharp(f))) = N_{\psi^\sharp(f)} = (N_R)_f = \widetilde{N_R}(D(f)) $$ as desired.
This follows from the exactness of the functor $\widetilde{\ }$ since by Lemma \ref{lemma-compare-constructions} we know that any map $\psi : \widetilde{M} \to \widetilde{N}$ comes from an $R$-module map $\varphi : M \to N$. (So we have $\Ker(\psi) = \widetilde{\Ker(\varphi)}$ and $\Coker(\psi) = \widetilde{\Coker(\varphi)}$.)
Suppose $\mathcal{F}_i$, $i \in I$ is a collection of quasi-coherent sheaves on $X$. By Lemma \ref{lemma-equivalence-quasi-coherent} above we can write $\mathcal{F}_i = \widetilde{M_i}$ for some $R$-module $M_i$. Set $M = \bigoplus M_i$. Consider the sheaf $\widetilde{M}$. For each standard open $D(f)$ we have $$ \widetilde{M}(D(f)) = M_f = \left(\bigoplus M_i\right)_f = \bigoplus M_{i, f}. $$ Hence we see that the quasi-coherent $\mathcal{O}_X$-module $\widetilde{M}$ is the direct sum of the sheaves $\mathcal{F}_i$. A similar argument works for general colimits.
This is kind of silly! Namely, by Lemma \ref{lemma-closed-immersion} we can identify $Z \to X$ with the closed subspace associated to a sheaf of ideals $\mathcal{I} \subset \mathcal{O}_X$ as in Definition \ref{definition-closed-subspace} and Example \ref{example-closed-subspace}. By our conventions this sheaf of ideals is locally generated by sections as a sheaf of $\mathcal{O}_X$-modules. Hence the quotient sheaf $\mathcal{O}_X / \mathcal{I}$ is locally on $X$ the cokernel of a map $\bigoplus_{j \in J} \mathcal{O}_U \to \mathcal{O}_U$. Thus by definition, $\mathcal{O}_X / \mathcal{I}$ is quasi-coherent. By our results in Section \ref{section-quasi-coherent-affine} it is of the form $\widetilde S$ for some $R$-module $S$. Moreover, since $\mathcal{O}_X = \widetilde R \to \widetilde S$ is surjective we see by Lemma \ref{lemma-extension-quasi-coherent} that also $\mathcal{I}$ is quasi-coherent, say $\mathcal{I} = \widetilde I$. Of course $I \subset R$ and $S = R/I$ and everything is clear.
Let $U \subset X$. Let $u \in U$. Pick an affine open neighbourhood $u \in V \subset X$. Because standard opens of $V$ form a basis of the topology on $V$ we see that there exists a $f\in \mathcal{O}_V(V)$ such that $u \in D(f) \subset U$. And $D(f)$ is an affine scheme by Lemma \ref{lemma-standard-open-affine}. This proves that every point of $U$ has an open neighbourhood which is affine.
Let $i : Z \to X$ be a closed immersion. Let $z \in Z$ be a point. Choose any affine open neighbourhood $i(z) \in U \subset X$. Say $U = \Spec(R)$. By Lemma \ref{lemma-closed-immersion-affine-case} we know that $i^{-1}(U) \to U$ can be identified with the morphism of affine schemes $\Spec(R/I) \to \Spec(R)$. First of all this implies that $z \in i^{-1}(U) \subset Z$ is an affine neighbourhood of $z$. Thus $Z$ is a scheme. Second this implies that $\mathcal{I}|_U$ is $\widetilde I$. In other words for every point $x \in i(Z)$ there exists an open neighbourhood such that $\mathcal{I}$ is quasi-coherent in that neighbourhood. Note that $\mathcal{I}|_{X \setminus i(Z)} \cong \mathcal{O}_{X \setminus i(Z)}$. Thus the restriction of the sheaf of ideals is quasi-coherent on $X \setminus i(Z)$ also. We conclude that $\mathcal{I}$ is quasi-coherent.
If $f$ is a closed immersion then $f(Y)$ is closed by definition. Conversely, suppose that $f(Y)$ is closed. By definition there exists an open subscheme $U \subset X$ such that $f$ is the composition of a closed immersion $i : Y \to U$ and the open immersion $j : U \to X$. Let $\mathcal{I} \subset \mathcal{O}_U$ be the quasi-coherent sheaf of ideals associated to the closed immersion $i$. Note that $\mathcal{I}|_{U \setminus i(Y)} = \mathcal{O}_{U \setminus i(Y)} = \mathcal{O}_{X \setminus i(Y)}|_{U \setminus i(Y)}$. Thus we may glue (see Sheaves, Section \ref{sheaves-section-glueing-sheaves}) $\mathcal{I}$ and $\mathcal{O}_{X \setminus i(Y)}$ to a sheaf of ideals $\mathcal{J} \subset \mathcal{O}_X$. Since every point of $X$ has a neighbourhood where $\mathcal{J}$ is quasi-coherent, we see that $\mathcal{J}$ is quasi-coherent (in particular locally generated by sections). By construction $\mathcal{O}_X/\mathcal{J}$ is supported on $U$ and equal to $\mathcal{O}_U/\mathcal{I}$. Thus we see that the closed subspaces associated to $\mathcal{I}$ and $\mathcal{J}$ are canonically isomorphic, see Example \ref{example-closed-subspace}. In particular the closed subspace of $U$ associated to $\mathcal{I}$ is isomorphic to a closed subspace of $X$. Since $Y \to U$ is identified with the closed subspace associated to $\mathcal{I}$, see Lemma \ref{lemma-closed-immersion}, we conclude that $Y \to U \to X$ is a closed immersion.
The equivalence of (1) and (2) is Sheaves, Lemma \ref{sheaves-lemma-restrict-basis-equivalence}. It is clear that (2) implies (3). Hence it suffices to prove that (3) implies (2). By Sheaves, Lemma \ref{sheaves-lemma-cofinal-systems-coverings-standard-case} and Lemma \ref{lemma-standard-open} it suffices to prove the sheaf condition holds for standard open coverings (Definition \ref{definition-standard-covering}) of elements of $\mathcal{B}$. Let $U = U_1 \cup \ldots \cup U_n$ be a standard open covering with $U \subset X$ affine open. We will prove the sheaf condition for this covering by induction on $n$. If $n = 0$, then $U$ is empty and we get the sheaf condition by assumption. If $n = 1$, then there is nothing to prove. If $n = 2$, then this is assumption (3). If $n > 2$, then we write $U_i = D(f_i)$ for $f_i \in A = \mathcal{O}_X(U)$. Suppose that $s_i \in \mathcal{F}(U_i)$ are sections such that $s_i|_{U_i \cap U_j} = s_j|_{U_i \cap U_j}$ for all $1 \leq i < j \leq n$. Since $U = U_1 \cup \ldots \cup U_n$ we have $1 = \sum_{i = 1, \ldots, n} a_i f_i$ in $A$ for some $a_i \in A$, see Algebra, Lemma \ref{algebra-lemma-Zariski-topology}. Set $g = \sum_{i = 1, \ldots, n - 1} a_if_i$. Then $U = D(g) \cup D(f_n)$. Observe that $D(g) = D(gf_1) \cup \ldots \cup D(gf_{n - 1})$ is a standard open covering. By induction there is a unique section $s' \in \mathcal{F}(D(g))$ which agrees with $s_i|_{D(gfi)}$ for $i = 1, \ldots, n - 1$. We claim that $s'$ and $s_n$ have the same restriction to $D(gf_n)$. This is true by induction and the covering $D(gf_n) = D(gf_nf_1) \cup \ldots \cup D(gf_nf_{n - 1})$. Thus there is a unique section $s \in \mathcal{F}(U)$ whose restriction to $D(g)$ is $s'$ and whose restriction to $D(f_n)$ is $s_n$. We omit the verification that $s$ restricts to $s_i$ on $D(f_i)$ for $i = 1, \ldots, n - 1$ and we omit the verification that $s$ is unique.
Say $X = \{x_1, \ldots, x_n\}$. Then $U_i = \{x_i\}$ is an open neighbourhood of $x_i$. By Lemma \ref{lemma-basis-affine-opens} it is affine. Hence $X$ is a finite disjoint union of affine schemes, and hence is affine by Lemma \ref{lemma-disjoint-union-affines}.
Assume that $X$ is reduced. Let $f \in \mathcal{O}_X(U)$ be a section such that $f^n = 0$. Then the image of $f$ in $\mathcal{O}_{U, u}$ is zero for all $u \in U$. Hence $f$ is zero, see Sheaves, Lemma \ref{sheaves-lemma-sheaf-subset-stalks}. Conversely, assume that $\mathcal{O}_X(U)$ is reduced for all opens $U$. Pick any nonzero element $f \in \mathcal{O}_{X, x}$. Any representative $(U, f \in \mathcal{O}(U))$  of $f$ is nonzero and hence not nilpotent. Hence $f$ is not nilpotent in $\mathcal{O}_{X, x}$.
Let $\mathcal{I} \subset \mathcal{O}_X$ be the sub presheaf defined by the rule $$ \mathcal{I}(U) = \{f \in \mathcal{O}_X(U) \mid f(t) = 0\text{ for all }t \in T\cap U\} $$ Here we use $f(t)$ to indicate the image of $f$ in the residue field $\kappa(t)$ of $X$ at $t$. Because of the local nature of the condition it is clear that $\mathcal{I}$ is a sheaf of ideals. Moreover, let $U = \Spec(R)$ be an affine open. We may write $T \cap U = V(I)$ for a unique radical ideal $I \subset R$. Given a prime $\mathfrak p \in V(I)$ corresponding to $t \in T \cap U$ and an element $f \in R$ we have $f(t) = 0 \Leftrightarrow f \in \mathfrak p$. Hence $\mathcal{I}(U) = \cap_{\mathfrak p \in V(I)} \mathfrak p = I$ by Algebra, Lemma \ref{algebra-lemma-Zariski-topology}. Moreover, for any standard open $D(g) \subset \Spec(R) = U$ we have $\mathcal{I}(D(g)) = I_g$ by the same reasoning. Thus $\widetilde I$ and $\mathcal{I}|_U$ agree (as ideals) on a basis of opens and hence are equal. Therefore $\mathcal{I}$ is a quasi-coherent sheaf of ideals. \medskip\noindent At this point we may define $Z$ as the closed subspace associated to the sheaf of ideals $\mathcal{I}$. For every affine open $U = \Spec(R)$ of $X$ we see that $Z \cap U = \Spec(R/I)$ where $I$ is a radical ideal and hence $Z$ is reduced (by Lemma \ref{lemma-affine-reduced} above). By construction the underlying closed subset of $Z$ is $T$. Hence we have found a closed subscheme with properties (a) and (b). \medskip\noindent Let $Z' \subset X$ be a second closed subscheme with properties (a) and (b). For every affine open $U = \Spec(R)$ of $X$ we see that $Z' \cap U = \Spec(R/I')$ for some ideal $I' \subset R$. By Lemma \ref{lemma-affine-reduced} the ring $R/I'$ is reduced and hence $I'$ is radical. Since $V(I') = T \cap U = V(I)$ we deduced that $I = I'$ by Algebra, Lemma \ref{algebra-lemma-Zariski-topology}. Hence $Z'$ and $Z$ are defined by the same sheaf of ideals and hence are equal.
Assume $f(Y) \subset Z$ (set theoretically). Let $\mathcal{I} \subset \mathcal{O}_X$ be the ideal sheaf of $Z$. For any affine opens $U \subset X$, $\Spec(B) = V \subset Y$ with $f(V) \subset U$ and any $g \in \mathcal{I}(U)$ the pullback $b = f^\sharp(g) \in \Gamma(V, \mathcal{O}_Y) = B$ maps to zero in the residue field of any $y \in V$. In other words $b \in \bigcap_{\mathfrak p \subset B} \mathfrak p$. This implies $b = 0$ as $B$ is reduced (Lemma \ref{lemma-reduced}, and Algebra, Lemma \ref{algebra-lemma-Zariski-topology}). Hence $f$ factors through $Z$ by Lemma \ref{lemma-characterize-closed-subspace}.
Let $A$ be a ring. For any ring homomorphism $\psi : A \to R$ there exists a unique prime ideal $\mathfrak p \subset A$ and a factorization $A \to A_{\mathfrak p} \to R$ where the last map is a local homomorphism of local rings. Namely, $\mathfrak p = \psi^{-1}(\mathfrak m)$. Via Lemma \ref{lemma-morphism-into-affine} this proves that the lemma holds if $X$ is an affine scheme. \medskip\noindent Let $X$ be a general scheme. Any $x \in X$ is contained in an open affine $U \subset X$. By the affine case we conclude that every pair $(x, \varphi)$ occurs as the end product of the construction above the lemma. \medskip\noindent To finish the proof it suffices to show that any morphism $f : \Spec(R) \to X$ has image contained in any affine open containing the image $x$ of the closed point of $\Spec(R)$. In fact, let $x \in V \subset X$ be any open neighbourhood containing $x$. Then $f^{-1}(V) \subset \Spec(R)$ is an open containing the unique closed point and hence equal to $\Spec(R)$.