I take it you're using this as your definition of function:
A subset $h \subset X \times Y$ is a function if, whenever $(x,y)$ and $(x,y')$ are in $h$, then $y=y'$.
This problem is complicated by the multiple set products, but if you work through it carefully, it's just a definition chase. [“Just” is in the eye of the beholder. With work, this kind of argument becomes routine.] The relation $h$ between $X = A\times A$ and $Y = B\times B$ is defined by
$$
h = \left\{((a_1,a_2),(b_1,b_2)) \mid (a_1,b_1)\in f,\ (a_2,b_2)\in g\right\}
$$
or, if you want,
$$
h = \left\{((a_1,a_2),(b_1,b_2)) \mid f(a_1) = b_1,\ g(a_2) = b_2)\right\}
$$
Suppose that $(x,y)$ and $(x,y')$ are in $h$. Then $x = (a_1,a_2)$, $y=(b_1,b_2)$, and $y' = (b_1',b_2')$ for suitable elements of $A$ and $B$, respectively. Then
\begin{align*}
(x,y) \in h &\implies (a_1,b_1) \in f \text{ and } (a_2,b_2) \in g \\
(x,y') \in h &\implies (a_1,b_1') \in f \text{ and } (a_2,b_2') \in g \\
\end{align*}
Since $f$ is a function, we know $b_1 = b_1'$. Since $g$ is a function, we know $b_2 = b_2'$. Therefore $y=y'$. Thus $h$ also satisfies the definition of function.