The crowd reaction is a part of it, but it is mostly due to the politics and the business, I guess.
If two skaters did equally good performances, I think Judges tend to let a home country skater win.
Like kimmie won over Miki at Skate American a few years ago.
Why? Because if so, the crownds can be happy, home country TV viewers can be happy, the home country federation can be happy and TV stations can be very happy due to the rating.
As ultimately this can elevate the popularity of the skating in that country, the federation can make more money and more young kids like to try figure skating.
So this is very important for them.
However, if a home country skater is a less known one, and his/her opponent is the international champion, judges tend to let the champ win as he/she got lots of fans all over the world,
in order to protect their "names" as their business effects cannot be ignored.
I remember Witt vs Ito at NHK in those days.
At that time, Kat was already a very popular Champ/Star and Midori was an upcoming skater.
After SP, Midori first and Kat second, and Kat landed only one or two clean triples for FS,
then Midori landed about six triples including triple-triple combo.
But still judges let Witt win.
That was the most outrageous judging I have ever seen in my life.