Fundamental group is abelian iff the fundamental group isomorphisms (a-hat) coincide
Hint: note that $f \ast \alpha := \gamma$ is a path from $x$ to $y$, and calculate $\bar{\gamma}$ by its definition. Then you are given:
$\hat{\gamma} ([g])= \hat{\alpha} ([g])$,
which should cancel to what you want.
Here's another way, quite similar to gnometorule's answer, but a bit different. Consider any $[f],[g] \in \pi_1(X,x)$. Your sufficient condition in particular implies $\hat{f} = \hat{g}$, so \begin{align} [f] = \hat{f}([f]) = \hat{g}([f]) = [\bar{g}] * [f] *[g] \ , \end{align} i.e. $[f]$ and $[g]$ commute.