Why does isomorphism follow from the natural bijection of Hom sets If X and Y are varieties, and Y is affine, there is a natural bijective mapping of sets
$$\operatorname{Hom}(X,Y)\xrightarrow{\sim}\operatorname{Hom}(A(Y),\mathscr O(X))$$
where the left are morphisms of varieties and the right are k-alg homs. It is always stated as ‘obvious’ that this implies that two affine varieties are isomorphic iff their coordinate rings are. But I don't see this! Is it implicit that the natural bijective mapping of sets only takes isos to isos and vice versa? If so, could someone explain to me how Hartshorne’s proof of Prop I.3.5 establishes this?
My issue, concisely, is that the bijective mapping assures us of at least one morphism X to Y and at least one Y to X if A(Y) and A(X) are iso as k-algs, but how do we know one of these maps is inverse to another?
 A: The short answer is that taking a variety $X$ to its $k$-algebra of regular functions $\mathscr{O}(X)$ defines a contravariant functor from the category of varieties to the category of $k$-algebras, and that this functor becomes a duality when restricted to the category of affine varieties.
More precisely: for any variety $X$, you associate its ring of regular functions $\mathscr{O}(X)$; for any morphism $f:X\to Y$ of varieties, you deduce a $k$-algebra homomorphism $f^*:\mathscr{O}(Y)\to \mathscr{O}(X)$.  This respects composition, in the sense that if $g:Y\to Z$ is another morphism of varieties, then $(g\circ f)^* = f^*\circ g^*$.  Moreover, if $1_X:X\to X$ is the identity morphism, then $1_X^* = 1_{\mathscr{O}(X)}$.  In other words, $\mathscr{O}(-)$ defines a contravariant functor from the category of varieties to the category of $k$-algebras.
Now, assume that $X$ and $Y$ are affine varieties.  If they are isomorphic, then of course so are $\mathscr{O}(X)$ and $\mathscr{O}(Y)$.  Assume the converse, and let $\varphi:\mathscr{O}(Y)\to \mathscr{O}(X)$ be an isomorphism, with inverse $\varphi^{-1}$.  By the bijective mapping in the beginning of your post, there exist morphisms of variety $f:X\to Y$ and $g:Y\to X$ such that $f^* = \varphi$ and $g^*=\varphi^{-1}$.  But then $(g\circ f)^* = \varphi\circ\varphi^{-1} = 1_{\mathscr{O}(X)}$ and $(f\circ g)^* = \varphi^{-1}\circ\varphi = 1_{\mathscr{O}(Y)}$.  Again by the bijection in your post, this implies that $g\circ f = 1_X$ and $f\circ g = 1_Y$.  This finishes the proof.
