There are some reasonable allowances for discrimination, such as in a scenario where you are a casting director for a big budget biopic film about Harriet Tubman. Obviously, you are not going to hire a white male for the title role and it would be ludicrous to entertain a suit by a white male actor that he was discriminated against. Generally, any job with a messaging, artistic, or branding association with it does allow for certain discrimination... you could make the argument that if you're selling product that promote quitting smoking, you would by your vary nature discriminate against employees smoking, especially if those smoking employees are your spokesperson.
In addition, Hate Crimes legislation in the United States is explicitly written to not take into account the aggressor's protected classes in relation to the victim's protected classes. If the aggressor's actions are motivate by hatred for the victim based on the victim being a member of a protected class. And it doesn't care if the victim is an actual member of the protected class. These laws will have a "perceived or otherwise" clause somewhere. If someone beats up a man for stereotypical homosexual behavior, but later learns that the individual has a smoking hot girlfriend and is just very flamboyant in mannerisms, it's still a hate crime because the accused perceived the victim as gay and was motivated by that assumption... doesn't matter if it was the wrong assumption.
In the case of workplace discrimination rules, there is also retalitory discrimination. Lets say a boss Alice is being investigated by HR because someone complained that she discriminates against men. Bob is the only man in the office, so Alice targets Bob for reporting her (she undercuts him at meetings, she passes him up for promotion, she gives him all the worst tasks, ect.). This is retaliation and Bob can claim he was discriminated against. This is perceived or otherwise as the person who really reported Alice was Carla, another woman, who did in fact hear Alice admit to discriminatory practices against men. Here, Carla has a case, because Alice discussed engaging in discriminatory hiring practices, and Bob has a case because Alice perceived him to be the one who complained, and was targeted for making such a complaint to HR (even though he didn't). This is mostly in employment law as in criminal law, retaliation typically comes in the form of Witness Intimidation or Jury Tampering (in fact, proving the latter is one of the few ways to get Double Jeopardy revoked... Can't be "twice be put into danger of life or limb" if you were never in danger in the first trial).