We do not need to assume $G_1,G_2$ connected. It is sufficient to assume that $G_1,G_2$ have no isolated vertices. Then for $(g,h),(g',h')\in V(G)$ pick $a\in G_1$ with $g\sim a$ and $b\in G_2$ with $h'\sim b$. Then $(g,h)\sim (a,b)\sim (g',h')$ shows that all distances in $G$ are $\le 2$ (and especially that $G$ is connected.