In proofs below we can assume $X_i$ are disjoint and $\bigcup_{i\in I} X_i$.
Theorem 1. Let $X = \bigsqcup_{i\in I} X_i$ where $X_i$ are non-empty. Then $X$ is realcompact iff $X_i$ is realcompact for all $i$ and $|I|$ is a (Ulam) non-measurable cardinal.
Proof: Suppose that $X$ is realcompact. Since closed subspaces of realcompact spaces are realcompact, $X_i$ is realcompact for all $i$. Take $x_i\in X_i$ for all $i\in I$, then $D = \{x_i : i\in I\}$ is a closed discrete subspace of $X$. Since a discrete space is realcompact iff it has non-measurable size, and $D$ is realcompact discrete space (as a closed subspace of $X$), it follows that $|D| = |I|$ is non-measurable.
Conversely suppose that $X_i$ are realcompact and $|I|$ is non-measurable. Equip $I$ with discrete topology, then $I$ is realcompact since it has non-measurable size. Since products of realcompact spaces are realcompact, $I\times \prod_{i\in I} X_i$ is realcompact. Fixing $y\in \prod_{i\in I} X_i$ and letting $X_i' = \{(i, x) : \forall_{j\neq i} x_j = y_j, x_i\in X_i\}$, each $X_i'$ is closed in $I\times\prod_{i\in I} X_i$ and homeomorphic to $X_i$, and $X_i'$ are pairwise disjoint. Consider the subspace $Y = \bigcup_{i\in I}X_i'\subseteq I\times\prod_{i\in I} X_i$. Since $\{i\}\times \prod_{j\in I} X_j \cap Y = X_i'$ is open in $Y$ for all $i\in I$, we see that $Y\cong \bigsqcup_{i\in I} X_i$. Because $I\times\prod_{i\in I} X_i\setminus Y = \bigcup_{i\in I} \{i\}\times X_i\cap (X\setminus X_i')$ is a union of open sets, $Y$ is closed. Since closed subspaces of realcompact spaces are realcompact, $Y$ is realcompact. $\square$
The converse of above theorem can also be proved via the following, where $\upsilon Z$ denotes the Hewitt realcompactification of $Z$:
Theorem 2. If $X_i$ are Tychonoff spaces, $|I|$ is non-measurable and $X = \bigsqcup_{i\in I} X_i$ then $\upsilon X = \bigsqcup_{i\in I} \upsilon X_i$.
Consider map $f:X\to I$ given by $f[X_i] = \{i\}$ and equip $I$ with discrete topology. Since $|I|$ is non-measurable, $I$ is realcompact, so there is an extension $g:\upsilon X\to I$ of $f$ to the Hewitt realcompactification $\upsilon X$ of $X$. Since $X_i\subseteq g^{-1}(i)$, we have $\overline{X_i}\subseteq g^{-1}(i)$, and since $\bigcup_{j\neq i} X_i\subseteq g^{-1}[I\setminus\{i\}]$ we have $\overline{\bigcup_{j\neq i} X_j}\subseteq g^{-1}[I\setminus\{i\}]$. Because $X$ is dense in $\upsilon X$ we have $\overline{X_i} = g^{-1}(i)$. Since $X_i$ are clopen in $X$, they are $C$-embedded in $X$ so that $\overline{X_i} = \upsilon X_i$. $\square$
Thanks to @Ulli for directing me to a conceptually easier proof for the converse of theorem 1.