it's okay to have thoughts that run counter to your values, and it's okay to have them in their entirety. let them run their course in private, in your head, in a diary, with a friend who understands this doesn't align with your core beliefs and is ready to talk through it with you.
it's not going to corrupt you. it's not going to somehow be psychically transmitted to the world at large. give yourself space to recognize that these are, in fact, your genuine thoughts and feelings, no matter how intensely uncomfortable that feels. recognize that you can let them be the dominant attitude in your mind for a few minutes without it affecting your behavior or compromising your integrity.
once you've gotten all of it out and seen the train of thought in its entirety, you can take a breath and step back to examine it from a distance. you can respond to it the way you would to a child who doesn't know better, non-judgmentally, trusting yourself to stay true to your pre-established values. and having processed it this way, you can feel closer to those values instead of feeling that tension between what you believe and the thoughts you refuse to acknowledge because they don't align with it.
"but it's bad to give any credence to harmful ideologies in the public discourse!" good thing this isn't the public discourse then.
"but prejudiced people aren't entitled to my empathy and education!" they are when they're you. it's non-negotiable that you have to live with you, therefore you are necessarily entitled to your own compassion.
"what would people think if they knew?" you don't have to tell anyone shit. your thoughts can be completely your own, and some of them should stay that way, but that doesn't mean they're evil to have, even if you hate the idea of acting on them. good news, you have free will and you don't have to act on them.
it's okay--good and healthy, in fact--to have pieces of yourself you wouldn't share online. no one can (or should have to) be 100% marketable and palatable inside and out 24/7. thoughts have no moral component. however, when pieces of our internal life are misaligned, it causes discomfort, and we can't address that discomfort if we don't acknowledge and examine it without judgment.