Note: I refer to the TSA in this answer, but it applies to pretty much anyone (who has some authority over you) that you deal with at the airport.
- What are my rights as a passenger to prevent such discrimination?
- How can I prevent airline employees from insulting me and my family in front of everyone at the airport?
Answering your question exactly as it is phrased; there is no "right to prevent discrimination", and you cannot stop anyone from issuing an insult without physically preventing them to speak.
The thing is, there's little you can do to stop it when it happens; but you can retroactively file a complaint or seek recompensation if you suffer undue consequences. To that extent, your question of how to stop it before/as it happens can only be answered with "you can't", at least not without severe consequences (such as making a bigger transgression yourself, being detained, or simply denied to board your flight).
I do understand where you're coming from. But the problem is that I can't tell you where to draw the line on taking a stand.
If you feel like you're being subjected to unfair treatment, but the TSA agent is adamant about their (let's call it misguided) position; do you want to stand on principle and risk not boarding your flight, or would you rather ensure that you can board your flight? I can't answer that for you. There are financial and moral ramification to either option, and you need to weigh your own priorities here.
If you want to avoid escalation while still attempting to avoid unfair treatment, you can ask for a supervisor to oversee/confirm what the TSA tells you.
But I've also heard about cases where this response actually caused an escalation, or where the supervisor shares the same (misguided) position and thus doesn't resolve the situation for you.
You can study up on the related rules and regulations, you could even take a printed version of it with you; but I can't guarantee that the TSA agent (or their supervisor) are going to not believe you at your word, or interpret your response as combative.
There is no universal surefire way to stop a TSA agent (or anyone else for that matter) from making a mistake. In the end, at the moment of dealing with them, they have the final say on whether you are allowed to board your flight. If they are wrong and you are unable to convince them of that in the moment, your only other option is to retroactively seek recompensation for unfair treatment.