This is something that has been on my mind a lot, as it is often my biggest critique of writing, and that is how few writers manage to write characters well. Some manage it brilliantly. Others manage it capably. Some fail so hard it makes me want to punch things. Ahem.
This is particularly exemplified when a non-minority is writing minority characters. It's a problem with cis-het writers writing queer characters. It's a problem with white writers writing people of colour. It's a huge problem with male writers writing women (and one that I see most often, likely because I'm most affected by it, more so than the others).
Look, writers, characters are important. At least, they should be. They are, after all, what drives your story. Without characters, you'd have nothing. So you need to pay respect to the crafting of characters.
And here's your biggest clue about characters. They're people. They might be blue-skinned and from another planet or something, but if they're characters, they're people.
Make sure they come across as people, and not a poor facsimile constructed entirely of idiotic stereotypes and tired tropes.
That means, dear writer, giving them dimension.
If you have a kick-arse warrior woman in your story, please understand that the warrior part of that is only an aspect of who she might be. It is entirely possible for a warrior to want to be a mother (or be a wonderful, loving mother in fact), or to be a devoted and doting wife. Being a warrior isn't the entirety of her. Don't shrink her down to one dimension.
A male fighter pilot is not merely a fighter pilot. Perhaps he loves gardening, or is a poet, or rescues dogs. Perhaps he play-acts the hero, but suffers from crippling low self-esteem. Maybe he's a single father, and his only thought is returning home to the child who adores him (or hates him. Take your pick). If he's the hero of your book, or simply a side-character, make him a whole person. Don't shrink him down to only one aspect of himself.
Similarly with queer characters, their queerness is not their whole selves. It is a part; founding, no doubt, as the queer experience will likely shape their character, just a straight experiences shape cis-het folk, but that's not all of them. Don't reduce a character to a single dimension.
Writing characters well takes skill. It's not easy.
I once had an argument with a bloke who whined "Writing women is hard!" and said that male writers shouldn't be held to such a "high" standard as getting women right, because that's tough (never mind that women are expected to write male characters well. Fucking double standards, man. It makes my blood boil to this day and that argument was years ago!). Well, no shit. Writing is hard. If you cannot do a character well because their gender, orientation or race is not your own, then you are not a good writer. It's a simple as that. Getting defensive won't change that fact. You know what will?
Some fucking effort.
Work on your craft.
Because everything hinges on your characters.