It is a myth, Xiphophorus do not truely change sex. Poecilids, like us have their sex determined genetically, they are born either male or female. All of them look the same when they are born but the males develop the gonopodium and in the case of swordtails, the sword, later.
To confuse matters these fish also develop at varying times, some of the males develop early and some later, from the same drop of fry. The early developing males are almost always smaller than the later developing males, usually significantly so. This doesn't happen with all species/strains of swordtails, but is common in many. One theory about this early/late development is that in some situations it is advantagous for the fish to mature early in lean times such as drought and famine. In times of plenty it is more advantagous for the bigger males who are obviously dominant over the faster developing smaller males. It can be confusing to see several males already developed and then several months later a new male or two appear. Also due to the common size differential between males and females of these species, it looks like a female changed to male as it is also larger. However this is not the case, it was always a male it just took a while to show it.
To confuse matters even further there are 3 sex genes in Xiphophorus which can skew sex ratios in this fish from the normal 50/50 ratio. In the right combination of these genes it is possible to get a drop of fry that all turn out to be males. I believe that this gene does not come into play in the wild but only in the aquarium where hybridizing of species and strains takes place.
Another apparent sex change, which is less common, occurs when an old female actually runs out of hormones. When this happens some of the male hormones, which were always present, cause an apparent sexual transformation. The anal fin may turn into the shape of a gonopodium and the fish grow a sword, the sword is usually much smaller than that of a true male, usually only a spike. This is similar to menopause in humans, where such things as facial hair start to occur. These fish are still females though they only express male characteristics. These fish may even appear to be mating but they have no sperm, and lack the proper gonopodium structure to deliver it, even if they did.
Innes reported sex change in Poecilids in his early writings as fact. We now know this is not true. You can find all kinds of stuff on the internet that states that these sex changes do happen in poecilids but it has been proven in controlled scientific environments that it does not. However this misconception lives on due to the reasons I already mentioned and thanks to the internet. You really have to do some research on this to find out the truth because if you just google it there will be all kinds of misinformation. I have been keeping swords for over 40 years and at one time I too believed they changed sex, after much research and observation I have to go with science on this and say they do not. I do know that sex change occurs in some saltwater fish and is quite common.