They figure it out. I had teachers make snide comments about Mormons because they overheard kids talking about seminary. My kids had teachers ask them to write "opinion" pieces on current events, then grade them down for having the wrong opinion. They can also just make it part of the curriculum to emphasize one political viewpoint over another. The kids with opposing views get worse grades. It happens at the collegiate level too. Teachers affect what kids believe in so many different ways it's easy to manipulate them in ways they want to. Indoctrination can happen in many different environments. It isn't the same as a racist teacher for many reasons. But that doesn't make it right.
Religious-political teachers are particular dangerous because they see what they are doing as "true", or don't even recognize it at all because it's just their nature. If they can ostracize a kid for having the "wrong"political views, well that's just serving the One True Party, which is only good and right, right? In fact, it isn't ostracizing, it's just the nature of good vs evil taking it's natural course.
It makes me think of the last vignette in The Ballad Of Buster Scruggs. A few people on a stage coach get into a discussion about what types of people there are. The hyper-religious woman makes it very clear there are only 2 types, and treats it as more than self-evident, but a virtual fact of nature and the universe. Per the holy bible there are only 2 types: the just and the sinners. Any argument to the contrary is met with derision and disgust. She can't even fathom a different point of view, let alone entertain it as even possibly meaningful. Same with a religious-political teacher. Students with opposing views will be put down in ways the teacher may not even realize because it's so ingrained in their being that they have the True Party, so all others are just wrong.