There are some big differences between being gay and 'being transgender'.
You are right that learning about gay people won't make a child gay. Also, being gay is not going to lead a child into pursuing harmful medical treatments.
Unfortunately, learning about 'transgender people' IS actually likely to make some children believe that changing sex is a valid option. And end up causing enormous damage to their healthy bodies.
Until about twenty years ago, only a tiny tiny number of children had gender dysphoria. (Mostly camp little boys who grew up to be happy, healthy gay men).
'Transgender' children seen at the Tavistock Gender Identity Clinic had massively disproportionate rates of being gay, having autism, or being looked after children (and thus likely having a history of significant trauma).
Teaching these children that 'some people are transgender' and that they can 'change sex' offers them a way of framing their distress as a simple problem: a problem with a horrific solution.