Yes. The criterion is that $f:G\to H$ be an $A_\infty$-map with respect to the $A_\infty$-structures on $G$ and $H$. The definition is given in Section 4 of Stasheff's Homotopy associativity of $H$-spaces, II (Trans. Amer. Math. Soc. 108 (1963), 293–312), in particular see Theorem 4.5 there.
There was some related discussion at the MO question Delooping maps between $H$-spaces.