At page 68 in Görtz & Wedhorn 's "Algebraic Geometry 1" book, there is the following text:
Proposition 3.5 (gluing of morphisms):
Let $X$,$Y$ be locally ringed spaces. For every open subset $U \subset X$, let $\operatorname{Hom}(U,Y)$ be the set of morphisms $(U,\mathscr O_{X \mid U}) \rightarrow (Y,\mathscr O_Y)$ of locally ringed spaces. Then $U \rightarrow \operatorname{Hom}(U,Y)$ is a sheaf of sets on $X$.
I think I may prove this proposition without the "locality" condition. I am not that confident since oftentimes I gave the wrong proof without noticing... So does this proposition holds if we replace all "locally ringed spaces" by "ringed spaces"?