For any map of rings $A \to B$, we want a map $Spec B \to Spec A$. There is also a geometric motivation that the map between two manifolds $\pi: M \to N$ has a pullback of a smooth function from $N$ to $M$ and for $\pi(x) = y$ if a function vanishes on $y$ then it will vanish on $x$ too.
Similarly, if we have a map $\Pi: A \to B$ where $A, B$ are two schemes, there is a pullback from the sheaves on $B$ to $A$
$$\mathcal{O}_B \to \Pi_* \mathcal{O}_A$$
and this also works well with the restrictions. Now, there are morphisms between the ringed spaces $(A,\mathcal{O}_A)$ and also works with restrictions. For example, $X \subset A$ be an open affine cover, then there is a morphism of ringed spaces
$$(X, \mathcal{O}_{A|X}) \to (A,\mathcal{O}_{A})$$
One also knows that the morphisms of ringed spaces admit compositions. Then one sees that the category of ringed spaces is formed (with objects being ringed spaces and the morphisms of ringed spaces as maps between them).
If taken an open covering over $A$ like $\cup_i\ \mathcal{U}_i = A$, then the morphisms agree on the overlap and there exists a unique map for each $\mathcal{U}_i \to B$ which will be $\Pi_i$. Now, a morphism of ringed spaces does not mean always a morphism of rings.
For reference, you know what to look for (the rising sea).
Before I end this post; the inaugural issue of Anveshanā (a bi-yearly magazine) is up now and contains, among many things, interviews and perspectives on mathematics, physics, and arts. It can be accessed at the following:
https://anveshanamagazine.github.io/ or link to full pdf.