Think functorially (i.e. don't think in terms of points). 2.4.2 of Hartshorne wants to show that $f,g: X \to Y$ are the same if $X$ is reduced, $Y$ is separated, and $f,g$ agree on an open dense subset $U$. I suspect you are trying to say something like $f \times g(U) \subset \Delta (X)$, but you don't need to do this pointwisely. Instead, try to think about this:
Consider the fibre product of the diagram $f \times g: Y \to X \times_S X$ and $\Delta:X \to X \times_S X$. You would get $j: (f \times g)^{-1}(\Delta(X)) \to Y$ is a closed immersion. You want to get the inclusion $i: U \to Y$ factors through $j$. For this, use the universal property of fibre product, then you would want to get a map $h: U \to X$ such that $\Delta \circ h = (f \times g) \circ j$. That $f$ and $g$ agree on $U$ would give you a natural candidate for $h$ - what should it be?
First, you should convince yourself that the question whether a given morphism $\operatorname{Spec} \mathcal{O}_{X,x} \to Y$ extends to an open neighborhood of $x$ comes down to the following question in commutative algebra:
Let $A$ and $B$ be two rings and let $\mathfrak{p}$ be a prime ideal of $A$. Does a given ring homomorphism $B \to A_\mathfrak{p}$ factor as $B \to A_f \to A_\mathfrak{p}$ for some $f \in A \setminus \mathfrak{p}$?
Note that there is no reason to hope that such a factorization always exists. Indeed, the answer to the above question might be "no".
But what if $B$ is a finitely generated $R$-algebra with $R$ a Noetherian ring, $A$ is an $R$-algebra and the given morphism is a morphism of $R$-algebras? This is the case you have to deal with in solving your exercise (I'll assume you are able to work out why - if you have trouble, just drop a comment). Then the above question is guaranteed to have a positive answer. Let's prove this. Write $B = R[T_1,\dotsc,T_n] / (g_1,\dotsc,g_m)$, denote the composite of the canonical projection $R[T_1,\dotsc,T_n] \twoheadrightarrow B$ with the given morphism $B \to A_\mathfrak{p}$ by $\varphi$ and write
$$\varphi(T_i) = \frac{a_i}{f_i}, \quad i=1,\dotsc,n \, ,$$
$$\varphi(g_j) = \frac{a_j'}{h_j}, \quad j=1,\dotsc,m \, .$$
Now, for each $j \in \lbrace 1,\dotsc,m \rbrace$, choose some $f_j' \in A \setminus \mathfrak{p}$ such that $f_j' a_j' = 0$ in $A$ (which exists since $\varphi(g_j) = 0 \in A_\mathfrak{p}$). I now claim that $f = \prod_{i=1}^n f_i \prod_{j=1}^m f_j'$ has the desired property, i.e. that the given homomorphism factors through $A_f \to A_\mathfrak{p}$. To see why, we first make use of the fact that, by construction, $f$ is a common denominator of all the $\varphi(T_i)$ and note that
$$ T_i \mapsto \frac{a_i \prod_{k \neq i} f_k \prod_{j=1}^m f_j'}{f}, \quad i=1,\dotsc,n$$
defines a morphism of $R$-algebras $R[T_1,\dotsc,T_n] \to A_f$ whose composite with $A_f \to A_\mathfrak{p}$ agrees with $\varphi$. In addition, we have, by construction, $a_j' f = 0$ for all $j \in \lbrace 1,\dotsc,m \rbrace$; thus, the morphism just defined maps each $g_j$ to $0$ and, as a consequence, factors over $B$.
Best Answer
As noted in the comments, $ \Delta(X) \subset Z $ is obvious.
It is enough to prove the other direction in the case that $ S = \operatorname{Spec} B $ and $ X = \operatorname{Spec} A $ are affine. Then $ X \times_S X = \operatorname{Spec}(A \otimes_B A) $ and let $ y \in Z $ correspond to the prime ideal $ P $ of $ A \otimes_B A $. Let $ i_1, i_2 : A \rightarrow A \otimes_B A $ be the maps $ i_1(a) = a \otimes 1 $, $ i_2(a) = 1 \otimes a $ and $ m : A \otimes_B A \rightarrow A $ the multiplication. Then the condition on $ y $ translates to: $ i_1^{-1}(P) = i_2^{-1}(P) = Q $ for a prime $ Q $ of $ A $ and the induced maps $ i_1^{\#}, i_2^{\#} : k(Q) \rightarrow k(P) $ are equal. In particular, evaluating at $ a \in A $, this implies that $ a \otimes 1 - 1 \otimes a \in P $ for all $ a \in A $.
Of course, the candidate element $ x \in X = \operatorname{Spec} A $ is the prime $ Q $ and the goal is to show that $ m^{-1}(Q) = P $. The following computation makes this clear: $$ a \otimes a' \pmod P = (a \otimes 1 - 1 \otimes a)(1 \otimes a') + 1 \otimes aa' \pmod P = 1 \otimes aa' \mod P $$ So if $ \gamma = \sum a \otimes a' $, then $ \gamma \pmod P = \beta \pmod P $ where $ \beta = \sum 1 \otimes aa' = 1 \otimes \sum aa' = 1 \otimes m(\gamma) $. Therefore $ \gamma \in P $ iff $ \beta \in P $ and from the fact that $ i_2^{-1}(P) = Q $, $ \beta \in P $ iff $ m(\gamma) \in Q $. This proves the assertion $ m^{-1}(Q) = P $ and hence $ y $ is the image of $ x = Q $ under $ \Delta $.
In the general case, as noted by KReiser in the comments, let $ W $ and $ U $ be open neighborhoods of $ x $ and $ s $ respectively. Then $ W \times_U W $ is an open neighborhood of $ y $ in the fiber product (This is because the maps $ \operatorname{Spec} k(y) \rightarrow X \times_S X \xrightarrow{p_i} W $ induce a map $ \operatorname{Spec} k(y) \rightarrow W \times_U W $).