You always have a canonical arrow $(X\times Z)\sqcup (Y\times Z) \to (X\sqcup Y)\times Z$, obtained from the universal properties of $\sqcup$ and $\times$ (there is a canonical arrow $X\times Z\to X\to X\sqcup Y$ and a canonical arrow $X\times Z\to Z$, so there is a canonical arrow $X\times Z\to (X\sqcup Y)\times Z$, and similarly for $Y\times Z$). But this arrow is not an isomorphism in general.
For a very simple example, consider the lattice M3, considered as a poset (a category with at most one arrow between any two objects). Here is a picture:

In a lattice, $\times$ is $\min$ and $\sqcup$ is $\max$, so we have $(x\sqcup y)\times z = 1\times z = z$, but $(x\times z)\sqcup (y\times z) = 0\sqcup 0 = 0$.
Actually, this is (almost) the universal obstruction: it happens that a lattice is distributive if and only if it contains no sublattice isomorphic to M3 or N5. N5 is another lattice that looks like this:

Here's another example, this time in a concrete category: distributivity fails in the category of abelian groups. In that category, $\times = \sqcup = \oplus$, so we have $(X\sqcup Y)\times Z \cong X\oplus Y \oplus Z$, but $(X\times Z)\sqcup (Y\times Z) \cong X\oplus Y\oplus Z^2$.