Gluing along closed subschemes Let $Z \to X$ be a closed immersion of schemes. Is it true that for every morphism $Z \to Y$, the pushout $X \cup_Z Y$ in the category of schemes exists? If yes, a) does it turn out to be simply sthe pushout in the category of locally ringed spaces, b) is the natural morphism $Y \to X \cup_Z Y$ a closed immersion?
In his paper "Gluing Schemes and a Scheme Without Closed Points", Karl Schwede studies such questions. In particular, he gives an affirmative answer if everything is affine (Theorem 3.4), but also for arbitrary schemes if we also assume that $Z \to Y$ is a closed immersion (Corollary 3.9). My intuition says that it should be also true if we drop this condition, but on the other hand the paper shows with some examples that our intuition may be wrong in the context of pushouts. I'm aware that colimits of schemes are not well-behaved in general, but in my research it would be useful to construct pushouts also when just one inclusion is a closed immersion.
As with this MO question, I think it is not sufficient just to say that some pushout does not exist just because you don't see one. I'm interested in rigorous proofs.
 A: In the positive direction, see D. Ferrand, "Conducteur, descente et pincement", Bull. SMF 131 (4), 2003, 553-585, especially Th. 5.4: the answer to all questions is yes if $Z\to Y$ is finite and every finite set in $X$ (resp. $Y$) is contained in an affine open subset.
More generally, assuming $Z\to Y$ affine, Theorem 7.1 gives a necessary and sufficient condition for the following to hold: (i) the pushout $X\cup_Z Y$ (as locally ringed spaces) is a scheme; (ii) $Y\to X\cup_Z Y$ is a closed immersion; (iii) $X\to X\cup_Z Y$ is affine.
The condition is this: for each $y\in Y$, the inverse image of $\mathrm{Spec(\mathcal{O}_{Y,y})}$ in $Z$ has a basis of affine open neighborhoods in $X$.
A: To complement Laurent Moret-Bailly and Karl Schwede's answers (10 years ago!), the pushout of a closed immersion $Z\to X$ along an affine morphism $Z\to Y$ always exists in the category of algebraic spaces. This is a special case of Theorem 1.8 of https://arxiv.org/abs/2205.08623.
A: See also Theorem 6.1 in Artin's Algebraization of Formal Moduli: II. Existence of Modifications, Ann. of Math. (2) 91 1970 88–135. 
Theorem 6.1:  Let $Y'$ be a closed algebraic subspace of an algebraic space $X'$, and let $f_0: Y' \to Y$ be a finite morphism. There is a unique maximal modification $f: X' \to X$, $Y \subset X$ whose restriction to $Y'$ is $f_0$. It is the amalgamated sum $X = X' \coprod_{Y'} Y$ in the category of algebraic spaces.
I had always thought that gluings in the generality mentioned above in Laurent Moret-Bailly's answer above only existed in the category of algebraic spaces.  I suspect I'm missing something obvious but I don't know what it is.  I'd deeply appreciate it if someone could set me straight on this.
A: Not an answer, but there is a beautiful instance of such a gluing used by Mazur in his famous Eisenstein ideal paper (page 50)
