Gender is a complicated subject, and so is the subject of what domesticated animals can perceive. So while a great many people have wondered whether their pet can distinguish between genders, the answer is — you guessed it — complicated.
One study attempted to look at whether dogs categorized people by "male" and "female," using voice and visual appearance as cues. (The study does not specify whether or not all the individuals were cisgender.) In the study, dogs sat opposite a speaker, and to each side of the speaker stood a man and a woman. The speaker would play the sound of a man's voice or a woman's voice, and the scientists looked to see if the dog looked toward the man or the woman each time. The study used 51 dogs from 17 different breeds.
So what did they learn? According to Scientific American, "the scientists found that some of the dogs looked at the person of the gender associated with the voice, whereas other dogs did not. Dogs that had come from homes where there were three or more adults were much better at looking at the 'correct' person than dogs that had come from a home with a single owner."
Some dog owners also report that their dog acts more fearful around men or women (with men, anecdotally, bearing the brunt of dog fearfulness). However, it's hard to say definitively whether the person's gender is really what a given dog is fearful of. For instance, the dog may fear tall people, and most of the tall people they've interacted with are men.
So, like with so many dog questions, "does my dog understand gender?" gets a resounding "ehh ... maybe."
What about cats, who probably care even less? Just like with dogs, there are some studies that suggest some cats behave differently toward men and women, but no definitive proof that they understand human gender.
A 2011 study out of the University of Vienna found that cats tended to approach and interact with female owners more frequently than they did with male owners, and concluded that the bond between women and their cats is more "intense" than the bond between men and their cats. (This study also did not specify whether the individuals used were cisgender, transgender or otherwise.)
However, that doesn't necessarily mean that cats understand the differences between human men and human women. Many factors may be at play here, including gendered expectations for (human) men and women. For example, the term "cat lady" exists, while there is no equivalent term for men. Moreover, men are generally encouraged to be less emotionally expressive than women are. Perhaps women feel more comfortable showing affection toward their cats than men do, which could lead to a stronger bond.
Beyond the aforementioned study, research on cats' perceptions of human gender is limited. Cats have never done anything that proves whether they understand differences in gender. They have, however, made it abundantly clear that they know who feeds them, and exactly when dinnertime is.