There’s a bit of a perverse-incentives problem in writing about marginalized groups.
If you write a marginalized character, people are going to criticize you for writing it offensively. This is true whether or not the way you wrote the character is actually offensive, because there is at least one person who thinks any possible depiction of a marginalized character is offensive. You write a nonbinary trans character, someone is going to write a passionate Tumblr post about how you’re catering to the genderspecials. You write the most transmedicalist-approved depressed and dysphoric trans character you can imagine, someone is going to complain about how you’re depicting transness as endless misery. You write a trans character who’s happy and okay with their body, and someone will complain that the character isn’t really even trans if they aren’t dysphoric. If you’re popular enough, it’s going to happen.
What’s worse, some of those criticisms will be right! It is difficult to accurately depict the way dysphoria affects trans people without showing our lives as unremitting sadness and self-hatred, and many writers will err too far on one end or another. Even the most well-meaning person can reproduce transphobic tropes, and even if you get a trans person to be a sensitivity reader sometimes they won’t catch it.
On the other hand, if you don’t write a marginalized character, no one is going to complain. There should be more trans characters in general, but (except in certain unusual circumstances, such as a book that takes place at Stonewall) there’s no reason to believe any specific book should have a trans character. No one is going to write “actually, the Dresden Files should totally have had a trans character in it,” and they’re definitely not going to repeat this for every single book series that happens to not have a trans character in it.
So I see a lot of young writers who are concerned about giving offense just not writing marginalized characters at all. And that’s really bad, because most of the time, an imperfectly written marginalized character is much better than no marginalized character at all.
I don’t mean to say that it’s impossible to write a marginalized character that is worse than no marginalized character at all. For example, you could write Ace Ventura: Pet Detective. (Transmisogyny at the link, and in the rest of this paragraph.) The world would be a better place if the authors of Ace Ventura: Pet Detective had not written a story with a transgender character in it. If you are writing a comedy in which one of the punchlines is a trans woman being sexually assaulted until the protagonist reveals that she has a penis, at which point there is an extended vomiting sequence because of how disgusting it is to have kissed a trans woman, and this is all played for laughs at the trans woman’s expense, I ask you on behalf of trans people everywhere not to write any more trans characters.
If, however, you would not do any of that, because that’s horrible, then you should write trans characters. Even though you’re going to mess up!
By contrast, consider Wanda from Neil Gaiman’s Sandman. Wanda is, in some ways, a problematically written character. About half her characteristics boil down to “Wanda is trans and faces transphobia.” Her birth surname is literally Mann. She cannot participate in a moon ritual because the universe itself limits certain rituals to people who menstruate. She dies tragically.
But would it be better if she didn’t exist?
Wanda is, after all, a sympathetically written character. She gets to call out the forces of magic itself for not thinking she’s a woman, and the narrative is pretty much on her side. Misgendering trans people is unambiguously depicted as wrong, and the fact that the wrong name is on her tombstone is shown to be a tragedy. She has interests and traits unrelated to being trans. Her body is not shown to be repulsive.
And… as far as I’m aware, Wanda was the first trans female character in a comic published by DC or Marvel. If Neil Gaiman had been like “hm, I guess I don’t know how to write trans people, I should make Wanda cis,” it would not have summoned an unproblematically written character out of the ether. Trans people would continue to not exist in mainstream comics, and once they did exist, they might be written by one of those people who thinks vomiting after you touch a trans person is the height of humor.
I am confident that Wanda made some cis people empathize with trans people who would never have empathized with them otherwise. And I’m sure I’m not the only trans person for whom Sandman was one of the first places we learned trans people even existed.
Of course, you should always try to improve your writing, and working on not perpetuating oppressive ideas is part of that. But the hurdle to clear before writing a marginalized character is better than not writing one is very low. You have to avoid making any particularly glaring factual inaccuracies. You have to not do the vomit thing. Most of all, you have to depict the character as a person, with thoughts and feelings and dreams and fears, someone whom the audience can empathize with (even if they’re a villain). If you do that, it’s okay to screw up on something more complicated. You’re still making life better for marginalized people.