It can happen that $Pic(X) = Pic(Y) = Pic(Z) = 0$ but $Pic(W) \neq 0$. For example, let $f: \mathcal{E} \to Z$ be a non-isotrivial family of elliptic curves, where $Z$ is a smooth rational curve. Then $Pic(\mathcal{E})$ is finitely generated, so by removing a finite number of (images of) sections of $f$ we obtain a surface $X \to Z$ such that $Pic(X) = 0$. Letting $Y = X$, I claim that $Pic(W) \neq 0$: To see this, let $\Delta$ be the diagonal inside $W = X \times_Z X$ so $L :=\mathcal{O}(\Delta) \in Pic(W)$. The restriction of $L$ to any fibre of the map $W \to Z$ is nonzero since the cohomology class of the diagonal in $E \times E$, where $E$ is any elliptic curve, remains non-zero when restricted to $E' \times E'$ where $E' \subset E$ is any non-empty Zariski open subset. In particular, $L \neq 0$, so $Pic(W) \neq 0$.