If I ended up being talked to by them I'd tell them what's up. "I don't want to talk to you, I don't believe in what that hat represents." Or catch their eye, look up at their hat and grimace/"yikes". You probably want to engage as little as possible, unless you're looking to spend your time arguing with the kind of person that wears a MAGA hat.
If it was more my party than theirs (like a house party), I'd tell them "that's not appropriate here."
If I were their boss in any way, or if it was my party, I'd tell them "we don't wear things like that here."
If they're far away in a park, I wouldn't say a thing. If they're close, one could say something like... "Hey. A lot of people here just wanna chill from politics for a moment. I don't want to see 'Hillary 2020' or "God is fake" t-shirts or anything. Would you please set it aside for a bit?" but don't make it sound like a question. Idk man. It's pretty egotistical from the start walking around like that.
If it were a friend, I'd tell them "c'mon dude, I don't wanna see that. For 1, it's distracting, ..."
imo it'd be really funny to tell them (in passing, to convey that you don't care about them enough to really engage, thus Winning the Social Interaction) that they're virtue signalling.