For marine flatworms, acting as the female partner means dedicating substantial metabolic resources to producing and nurturing offspring.
By contrast, producing sperm is relatively inexpensive.
From an evolutionary perspective, it is far more efficient to fertilize another individual than to carry the burden of producing eggs.
As a result, both partners would prefer to function as males.
But reproduction requires one individual to accept the female role.