A certain Chassidus has the minhag of spitting on the ground in shul during Aleinu Leshabeach where it refers to the other nations bowing to “lehevel varik”.
I was told this minhag comes all the way back from the Taz Yoreh Deah 179:8. I haven’t looked into it myself, but wanted to know if this is in fact a true minhag from those times how could it be instituted at the expense of kavod for the Shul and Hashem? People wouldn’t spit on the ground in their home, so how can there be a heter to spit in a shul?
The spitting that it referred to here is a minute amount, just enough to call it spitting, and the reason it should be so little is like you wrote, because it is a shul and spitting otherwise is very disrespectful. However as the Taz writes, that everyone knows that the spitting is being done as an embarrassment to the avoda zara, and therefore it is considered a honor for shomayim. Therefore it isn’t considered disrespectful to spit on Hashem’s enemies, to show that we don’t like them.
Orchos Rabeinu 2 pg. 68, See Emek Bracha (Shela Hakadosh) Shemona Esrei 40, that writes not to spit because it may be done at the wrong time and because the gentile will be upset by it, but it isn’t because it is disrespectful to the shul. Piskei Teshuvos 132-8.