Is It Legal To Write An Stipulation In A Will To Exclude A Person If They Are Lgbtq?

I did some googling for this and couldn't find an answer to this question.
My parents are now recently retired and both have health issues. I recently visited and they discussed whether I would be the executor of their will. My mother is also a very hateful person, and mentioned that if I am executor, I will have to do things I may not want to do.
Specifically, she is going to write an exclusion that my nieces (there are two) will not get anything if either of them are LGBTQ, specifically trans. I was taken aback by this and in that moment told her I could not execute something so vile and hateful. My nieces are barely teenagers, and have never expressed that they are LGBTQ (not that it matters). My mother is just doing this because she hates LGBTQ people.
Is it legal for an exclusion like this to exist? My parents are retired in South Carolina.
Edit: I've received good responses and am satisfied with the advice. Mods, you may lock this if you choose.
[link] [comments]