Because he was in love with a heracross in season 23 episode 33 and It was shown that the heracross did not have a heart shaped horn like the female ones have and because you can’t be queer in the Pokémon world she is female
^^^ Actually I remember that the wild Ditto I tried to get for trading used attract on my pokemon (who had gender) and it worked, despite the wiki says the player's Ditto can't use it.