Now all this might sound a bit fool hardy for these male spiders to sacrifice their lives for the sake of sex, but their desire to pass on their genes to the next generation, ensuring immortality, is greater than their desire to live longer but ultimately mortal lives. Also sacrificing themselves to the female provides her with extra nutrition, improving her chances of fathering his offspring. In contrast, there is a species of praying mantis which only ejaculates once its head has been bitten off. Other animals like bees, ants, termites and wasps also exhibit selfless behaviour, by also sacrificing their lives for the good of the species or the colony. When tarantulas are young they all look like females, but as the get older, their sex becomes more obvious.
Adult males have hooks on their front legs and their stomachs are smaller than females'.
So tarantulas don't actually change sex when they moult, it's just the differences between male and females become more obvious.