Some good answers here....but the variables are too many to generalize. When confronted by a rude foreigner, or seeing it happen to others, I have sensed these reasons (in no particular order).
1) In the boondocks there seems to be greater suspicion toward the encountered foreigner. Maybe a feeling that they aren't special anymore.
2) Some react to the other's nationality without bothering to get to know the person.
3) Drunk, overly opinionated, or just a lousy attitude always. (Probably the only reason that can't be overcome with time)
4) Jealousy. Better money, house, woman/women, life, even looks.
5) "Class" issue, upbringing, blue collar/white collar, background differences.
I might be wrong but those seem to be the reasons I've witnessed or experienced. Although I keep to myself for the most part I'm not adverse to striking up a conversation with another foreigner I meet, knowing it will likely just be that one time I engage them. Often they have some valuable information to share or maybe a contact or two that will make your life a bit easier here. For the real <deleted> out there (and in here) there is not much we can do about them other than to ignore them. It's too bad though as we likely have more in common with each other than mr. somchai on the street.