Does the inclusion from affine schemes into schemes preserve pushouts?

The functor $\textrm{Spec} : \textbf{CRing}^\textrm{op} \to \textbf{Sch}$ does not preserve pushouts, and this is intentional. Indeed, consider the projective line $\mathbb{P}^1_k$ over a field $k$. This is obtained by gluing two copies of $\mathbb{A}^1_k$ along $X = \mathbb{A}^1_k \setminus \{ 0 \}$, and in fact we have a pushout diagram in $\textbf{Sch}$: $$\tag{1} \begin{array}{ccc} X & \to & \mathbb{A}^1_k \\ \downarrow & & \downarrow \\ \mathbb{A}^1_k & \to & \mathbb{P}^1_k \end{array}$$ Applying the global sections functor to this diagram, we get a pullback diagram in $\textbf{CRing}$: $$\tag{2} \begin{array}{ccc} k & \to & k[t^{-1}] \\ \downarrow & & \downarrow \\ k[t] & \to & k[t, t^{-1}] \end{array}$$ However, if we apply $\textrm{Spec}$ to diagram (2) we do not get back to diagram (1) because $\mathbb{P}^1_k$ is not affine. So we have the desired counterexample.


The pushout of schemes even doesn't have to exist at all. There is an example which I have learnt from Anton Geraschenko and Brian Conrad.

If $X$ is an integral scheme with a non-closed generic point $\eta$ such that the closed points are dense in $X$ (for example a nontrivial affine variety), then the coequalizer of $\eta \rightrightarrows X \sqcup X$ does not exist in the category of schemes. And every coequalizer in a category with coproducts can be described as a pushout, here it is the pushout of $\eta \sqcup \eta \to X \sqcup X$ and $\eta \sqcup \eta \to \eta$. Hence, for example, $\mathrm{Spec}(k(x)) \leftarrow \mathrm{Spec}(k(x) \times k(x)) \to \mathrm{Spec}(k[x] \times k[x])$ has no pushout at all.

A sufficient condition (but not necessary) for $\mathrm{Spec}(R \times_T S) = \mathrm{Spec}(R) \cup_{\mathrm{Spec}(T)} \mathrm{Spec}(S)$ is that $R \to T$ is surjective, see the paper Gluing Schemes and a Scheme without Closed points by Karl Schwede.

In general, pushouts of schemes are quite delicate and it is quite hard to say something about them. A common mistake (even in published papers) is to assume that the forgetful functor to ringed spaces preserves pushouts. Although this may be true for some reason, it is not clear a priori. This means that it is quite hard to check if a pushout, or more generally colimits, exists or not. For example, it is quite easy to see that the colimit of $\mathbb{A}^0 \hookrightarrow \mathbb{A}^1 \hookrightarrow \mathbb{A}^2 \hookrightarrow \dotsc$ in the category of ringed spaces is not a scheme, but of course this does not prove that there is no colimit in the category of schemes. I only know the following: If a colimit of schemes $X = \mathrm{colim~}_i X_i$ exists, then $\Gamma(X,\mathcal{O}_X)=\mathrm{lim~}_i \Gamma(X_i,X_i)$. The reason is that $\Gamma : \mathsf{Sch} \to \mathsf{CRing}^{\mathrm{op}}$ is left adjoint to the functor $\mathrm{Spec}$, therefore preserves all colimits. But a priori we know nothing about the whole structure sheaf of $X$ or the topology of $X$.


For a simple example where the pushout of affine schemes is not preserved by the inclusion to schemes, see my answer to https://mathoverflow.net/questions/29311 .