I will explain slightly further.
As we learned from Undyne talking about Napstablook, the ghosts are genderless.
But Mettaton and Mad Mew Mew have genders.
Their 'vessels' have genders, so it's assumed that the ghosts' gender is determined by the gender of the vessel.