Let $A\to B\to C, D\to C$ be morphisms in any category, then there is a general natural equivalence:
$$A\times_B(B\times_C D) \stackrel {\simeq}{\longrightarrow } A\times_C D,$$
which can be easily checked by the universal property of fiber product.
So in the above case we have:
$$f'^{-1}(p') = \mathrm{Spec}\,k(p')\times_{S'} (S' \times_S X) \simeq \mathrm{Spec}\,k(p') \times_S X \\\simeq \mathrm{Spec}\,k(p') \times_{\mathrm{Spec}k(p)}(\mathrm{Spec}\,k(p)\times_S X)= \mathrm{Spec}\,k(p')\times_{\mathrm{Spec}k(p)}f^{-1}(p).$$
The fiber $f^{-1}(p)$ can be any given scheme over $k(p)$, (for every $X$ over $k(p)$, the fiber of the morphism $X\to \mathrm{Spec}\,k(p)\to S$ over $p$ is equal to $X$) so your problem reduces to consideration of base changes over the field extension: $k(p')/k(p)$. And this base extension is always isomorphism iff $k(p) \to k(p')$ is isomorphism i.e. $k(p) = k(p')$. (You can see it by assuming $f^{-1}(p) = \mathrm{Spec}\,k(p)$.)
In the case that $S'\to S$ is morphism of smooth (irreducible) curves, $p$ and $p'$ are both either a close point ($k(p), k(p')$ finite over $k$) or both generic ($k(p), k(p')$ f.g with tr.deg =1 over $k$). So you should only check that $[k(p'):k(p)] =1 $ for the isomorphism of fibers in the general case. In the second case this is equivalent to the bi-rationality of $g$ and in the first case this condition is obviously true if $k$ is assumed to be algebraically closed.
EDIT: I want to add that the relevant parts of EGA to compare are [EGAI, Thm. 1.7.3], which is the analogue of [Hartshorne, II, Prop. 2.3(c)], and [EGAI, Prop. 2.2.4], which is the analogue of your exercise. This proof is similar to the other answer.
[EGAInew, Prop. 1.6.3] is what I am paraphrasing below. It is also [EGAII, Err$_\mathrm{I}$, Prop. 1.8.1], with attribution to Tate.
I won't write down all of the details, but here is another way to approach the problem, which I think is easier, since it avoids the issue with trying to cover $X$ by open affines and glueing morphisms together. We use that the category of schemes is a full subcategory of the category of locally ringed spaces. It suffices to show
\begin{align*}
\alpha\colon \operatorname{Hom}_\mathsf{LRS}(X,\operatorname{Spec} A) &\longrightarrow \operatorname{Hom}_\mathsf{Ring}(A,\Gamma(X,\mathcal{O}_X))\\
(f,f^\#) &\longmapsto f^\#(\operatorname{Spec} A)
\end{align*}
is bijective. We construct an inverse map
$$
\rho\colon \operatorname{Hom}_\mathsf{Ring}(A,\Gamma(X,\mathcal{O}_X)) \longrightarrow \operatorname{Hom}_\mathsf{LRS}(X,\operatorname{Spec} A)
$$
as follows. Let $\varphi\colon A \to \Gamma(X,\mathcal{O}_X)$ be given. Define
$$
f \colon X \to \operatorname{Spec} A, \quad x \mapsto \{s \in A \mid \varphi(s)_x \in \mathfrak{m}_x\}
$$
where $\varphi(s)_x$ is the image of $\varphi(s)$ in the stalk $\mathcal{O}_{x,X}$ and $\mathfrak{m}_x \subseteq \mathcal{O}_{x,X}$ is the maximal ideal of $\mathcal{O}_{x,X}$. Note the set on the right is a prime ideal. The map $f$ is continuous since $f^{-1}(D(r)) = \{x \in X \mid \varphi(r)_x \notin \mathfrak{m}_x\} = D(\varphi(r))$. We define the map $f^\#$ of structure sheaves; since $D(r)$ form a basis of $\operatorname{Spec} A$, we construct the morphism on each $D(r)$ and then glue. We define $f^\#(D(r))$ to be the top arrow in the diagram
$$
\require{AMScd}
\begin{CD}
A_r @>f^\#(D(r))>\exists!> \mathcal{O}_X(f^{-1}(D(r)))\\
@AAA @AAA\\
A @>\varphi>> \mathcal{O}_X(X)
\end{CD}
$$
induced by the the universal property of localization [Atiyah-Macdonald, Prop. 3.1], where the hypotheses for the universal property hold since $\varphi(r)$ is invertible in $\mathcal{O}_X(f^{-1}(D(r)))$ by definition of $f$. The morphisms on each $D(r)$ glue together since the maps $f^\#(D(r))$ were constructed uniquely by the universal property above, hence on any intersection $D(rs)$ they must match.
To show $\alpha$ and $\rho$ are inverse to each other, note $\alpha \circ \rho = \mathrm{id}$ is clear by letting $r = 1$ in the diagram above. This implies $\alpha$ is surjective, so it remains to show $\alpha$ is injective. Let $\varphi\colon A \to \Gamma(X,\mathcal{O}_X)$, and let $(f,f^\#)$ such that $\alpha(f,f^\#) = \varphi$. Then, we have the diagram
$$
\begin{CD}
A_{f(x)} @>f^\#_x>> \mathcal{O}_{x,X}\\
@AAA @AAA\\
A @>\varphi>> \mathcal{O}_X(X)
\end{CD}
$$
by taking the direct limit over all open sets $D(r)$ containing a point $x$. Since the map $f_x^\#$ is local, we have $(f_x^\#)^{-1}(\mathfrak{m}_x) = \mathfrak{m}_{f(x)}$, hence $f(x) = \{s \in A \mid \varphi(s)_x \in \mathfrak{m}_x\}$ as desired by using the commutativity of the diagram. The uniqueness of $f^\#$ also follows from this diagram since if $(g,g^\#)$ is any other map $X \to \operatorname{Spec}A$ such that $\alpha(g,g^\#) = \varphi$, then $f^\#_x = g^\#_x$ for all $x$, hence they must be the same morphism.
Best Answer
Okay, let's take a prime ideal $I$ of $\mathbb{Z}[x]$ and consider its pre-image under $\iota: \mathbb{Z} \rightarrow \mathbb{Z}[x]$. The result is a prime ideal of $\mathbb{Z}$, so either $(0)$ or $(p)$.
Let's consider the case $\iota^{-1}(I)=p\mathbb{Z}$, i.e. $I\cap \mathbb{Z} = (p)$. This happens if and only if $I$ contains $p\mathbb{Z}[x]$. Now the ideals of $\mathbb{Z}[x]$ containing the latter are in one-to-one correspondence with the ideals of $\mathbb{Z}[x]/p\mathbb{Z}[x] \cong \mathbb{F_p}[x]$ through the quotient map $\mathbb{Z}[x] \rightarrow \mathbb{F}_p[x]$. This shows that the fibre of $\pi: \text{Spec} \mathbb{Z}[x] \rightarrow \text{Spec}{\mathbb{Z}}$ over $(p)$ is in bijection with $\text{Spec}\mathbb{F}_p[x]$.
Now consider the case where $\iota^{-1}(I) = (0)$. In other words $I \cap \mathbb{Z} = (0)$. Let $S$ be the multiplicative set of non-zero integers in $\mathbb{Z} \subset \mathbb{Z}[x]$. Then $I \cap S = \emptyset$, and such ideals $I$ of $\mathbb{Z}[x]$ are in one-to-one correspondence with the ideals of the ring $\mathbb{Z}[x]S^{-1} $ through the localization map $\mathbb{Z}[x] \rightarrow \mathbb{Z}[x]S^{-1}\cong \mathbb{Q}[x]$. This shows the fibre over $(0)$ is in bijection with $\text{Spec}\mathbb{Q}[x]$.