unironically this is a thing that does happen irl for some animals and pretty much all plants. obvious example is the clownfish. the scientific term for this is in these species (mostly ocean animals from what I can tell) is sequential hermaphroditism and its really interesting to me because i like to study the creatures! There's tons of different types too, sometimes like OP said it is just a matter of sex changing with age and sometimes it has to do with external factors such as climate, resources available, competition for mates, ect.
just like irl I also think troll attitudes about transness on alternia stem more from misogyny; and unlike irl, the influence of doc scratch. troll gender should be 8x more confusing and convoluted than human gender, which is already pretty confusing. Kind of like how the quadrants suck ass and confuse everyone including most of the trolls but altenian society enforces them anyways or the drones kill you, they would probably have like. gender quadrants. or something. all i know is that its really transgender.