No, take $Z$ a connected space for which $\Omega Z$ is nothomotopy commutative but $Z$ has no $A_\infty$ multiplication, e.g. $Z$ could be an $H$-space which doesn't have the homotopy type of a loop space, and. If $f=g=\mathrm{Id}_Z$. Then you are asking if, then the multiplication $\Omega Z \times \Omega Z \rightarrow \Omega Z$ is an $A_\infty$$A_2$-map by the hypothesis of homotopy commutativity and and Eckmann-Hilton argument. If it were an $A_\infty$ map, we could apply the bar construction to achieve a map $B(\Omega Z \times \Omega Z)=B\Omega Z \times B\Omega Z \rightarrow B \Omega Z$ which is an $A_\infty$ multiplication. Since $Z$ is connected $B\Omega Z \simeq Z$, so we have produced an $A_\infty$ multiplication on $Z$. However, an $A_\infty$ multiplication on $Z$ implies it is a loop space, which contradicts our assumption.