Let $G=C_{n_1}*\cdots*C_{n_k}=\langle a_1,\cdots,a_k\mid a_1^{n_1}=\cdots=a_k^{n_k}=1\rangle$ be a free product of finitely many finite cyclic groups. Given a word $g=g_1\dots g_n\in G$, is there an algorithm to determine whether $g$ is a commutator in $G$, i.e. whether there exist $a,b\in G$ such that $g=aba^{-1}b^{-1}$?
A specific example that I am interested in is $G=C_4*C_4$ and $g=(a_1a_2a_1a_2^{-1})^2$. I believe that this element is not a commutator, but I don't see a simple proof.
The only "test" I currently know of is that $g$ must reduce to the identity in the Abelianization of $G$, but of course, this only says that $g$ is a product of commutators and not necessarily a single commutator.
For your example, the following (very naive) computation in Magma seems to show that the image of your element $g$ in a finite quotient of $G = C_4 * C_4$ of order $256$ is not a commutator, so it cannot be a commutator in $G$ itself.
In fact $g$ is the unique element in $[P,P]$ that is not a commutator.