TITLE: A scheme is affine iff the natural map $X\to \operatorname{Spec}\Gamma(X)$ is an isomorphism
QUESTION [6 upvotes]: We know that the functor $\operatorname{Spec}: \mathsf{Rings}^{\text{op}}\to \mathsf{Schemes}$ is right adjoint to the global section functor $\Gamma: \mathsf{Schemes}\to  \mathsf{Rings}^{\text{op}}$. So there is a bijection
$$
\operatorname{Hom}(X, \operatorname{Spec} A) \to \operatorname{Hom}(A, \Gamma(X))
$$
which is natural in both variables. So if $X$ is a scheme, then we can set $A=\Gamma(X)$ and we get a bijection $\operatorname{Hom}(X, \operatorname{Spec} \Gamma(X)) \simeq \operatorname{Hom}(\Gamma(X), \Gamma(X))$. As a result, the identity map $\Gamma(X)\to \Gamma(X)$ gives rise to a natural map $X\to\operatorname{Spec}(\Gamma(X))$.  My question is this:

If $X$ is affine, why does it follow that the natural map $X\to \operatorname{Spec}(\Gamma(X))$ is an isomorphism?

The proof probably uses some formal naturality properties of adjoints, but nobody usually bothers to explicitly write this stuff down! So I am also tagging (category-theory) to attract experts from there. I would very much appreciate it if someone could give a complete explanation.
Motivation. This result is pretty useful. For example, we need this fact to conclude that $X=\mathbb{A}^2-\{0, 0\}$ is not affine. Indeed, the standard proof goes by showing $\Gamma(X)=\mathbb{C}[x,y]$, but then the natural map $X\to \operatorname{Spec}(\Gamma(X))=\mathbb{A}^2$ is not an isomorphism, so $X$ is not affine.

REPLY [3 votes]: $\DeclareMathOperator{\Spec}{Spec}$
Let $X = \Spec A$ for some ring $A$. Then $\Gamma(X)=A$ by definition of the structure sheaf on $X$. Applying $\Spec$ to the identity map $\Gamma(X)\rightarrow A$ yields an isomorphism of affine schemes
$$
f\colon X = \Spec A \longrightarrow \Spec \Gamma(X),
$$
since $\Gamma(X)\rightarrow A$ is an isomorphism and $\Spec$ is functorial. Also note that $f$ is indeed the canonical morphism $X\rightarrow \Spec \Gamma(X)$.