When is a closed immersion an isomorphism? Today I learned that if $f:X \to Y$ is a closed immersion of schemes, then the sheaf map $f^\#: O_Y \to f_* O_X$ is surjective, which is equivalent to $f^\#_x: O_{Y,f(x)} \to O_{X,x}$ being surjective for all $x \in X$. So the only thing that remains for $f$ to be an isomorphism is the injectivity of $f^\#_x$ for all $x \in X$. I wonder if there are any natural conditions that give this injectivity (and hence make a closed immersion into an isomrphism).
 A: Just to get this off of the answered list, let me just elaborate on what I said in the above comment.
Namely, let us say that $f\colon X\to Y$ is a clopen embedding if $f(X)\subseteq Y$ is a clopen(=closed and open) subset, and $f:X\to f(X)$ is an isomorphism, where $f(X)$ is given the open subscheme structure. Evidently a clopen embedding is an isomorphism if and only if it is surjective.

Observation: Let $f\colon X\to Y$ be a closed embedding of schemes. Then, $f$ is a clopen embedding if and only if $f$ is locally
of finite presentation and flat.

Proof: If $f$ is a clopen embedding then it is flat and locally of finite presentation (in fact see here for a much more interesting result). For the converse result, if $f$ is locally of finite presentation and flat then it is an open embedding by this (or the previously linked result!). Indeed, the only thing to observe is that being locally of finite presentation implies finite presentation since $f$ is automatically quasi-compact, being a closed embedding. The claim then follows, as $f$ being an open embedding implies that $f\colon X\to f(X)$ is an isomorphism, and $f(X)$ is clopen since $f$ is both an open and closed embedding. $\blacksquare$
Let me just note that both conditions are necessary:

*

*if $Y$ is locally Noetherian, then any closed embedding is (locally) of finite presentation, so it's easy to give counterexamples to the claim if we remove the flat hypothesis (e.g. $\mathrm{Spec}(k[x]/(x))\to \mathrm{Spec}(k[x])$,

*more surprisingly you cannot remove the locally of finite presentation property, and in fact the closed embedding $\mathrm{Spec}(R/I)\to\mathrm{Spec}(R)$ is flat precisely when $I$ is pure (see here), and the existence of closed but not clopen embeddings into connected schemes is quite difficult (c.f. [Proposition 5.4 + Proposition 7.2, Lazard]).

