This is a particular case of a more general rigidity result, whose proof (similar to the one given in abx's answer) can be found in Lemma 3.8 of
Fabrizio Catanese F. Catanese, Fibred surfaces, varieties isogenous to a product and related moduli spacesFibred surfaces, varieties isogenous to a product and related moduli spaces, Amer. J. Math. 122 (2000), no. 1, 1-44.
Proposition. Let $f \colon C_1 \times C_2 \longrightarrow B_1 \times B_2$ be a surjective holomorphic map between products of curves. Assume that both $B_1$ and $B_2$ have genus $\geq 2$. Then, after possibly exchanging $B_1$ with $B_2$, there are holomorphic maps $f_i \colon C_i \to B_i$ such that $$f(x, \, y) = (f_1(x), \, f_2(y)).$$