A scheme is affine iff the natural map $X\to \operatorname{Spec}\Gamma(X)$ is an isomorphism 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.
 A: $\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)$.
A: Consider an arbitrary left adjoint $L : C \to D$ with right adjoint $R$. In the situation at hand $C$ is schemes, $D$ is affine schemes, $R$ is the inclusion of affine schemes into schemes, and $L$ is the affinization functor $X \mapsto \text{Spec } \Gamma(X)$. An adjunction comes with a unit natural transformation
$$\eta : \text{id}_C \to RL$$
and a counit natural transformation
$$\varepsilon : LR \to \text{id}_D.$$

Exercise 0: Any adjunction defines an equivalence of categories between the subcategory of $C$ consisting of objects $c \in C$ such that the unit $\eta_c : c \to RLc$ is an isomorphism and the subcategory of $D$ consisting of objects $d \in D$ such that the counit $\varepsilon_d : LRd \to d$ is an isomorphism.

In general it's an interesting problem to identify what these subcategories are.

Exercise 1: $R$ is fully faithful iff the counit $\varepsilon_d : LRd \to d$ is always an isomorphism.
Exercise 2: Exercise 1 implies that if $R$ is fully faithful, then the adjunction above restricts to an equivalence of categories between $D$ and the subcategory of $C$ such that the unit $\eta_c : c \to RLc$ is an isomorphism.

Because the inclusion of affine schemes into schemes is indeed fully faithful, it follows that a scheme is affine iff $X \mapsto \text{Spec } \Gamma(X)$ is an isomorphism.
There are several ways to describe this situation. One is that $D$ is a reflective subcategory of $C$. Another is that the monad $M = RL$ on $C$ induced by the above adjunction is idempotent, and $D$ ends up being identified with algebras over this monad. A familiar example is the adjunction between groups and abelian groups: here we have that a group $G$ is abelian iff the abelianization map $G \to G/[G, G]$ is an isomorphism.
