On the origins of sexual dimorphism in butterflies