I've seen many junior employees hold the wrong expectation of HR in terms of who's on their side. I can't directly fault them at the times that the company is pushing that version of the world.
"Friend or foe" is a super reductive way to look at it, and will limit your ability to actually understand what is going on.
To the generic employee, HR thinks of you the same way a farmer treats cattle. Within the range you are judged to be worth, they want you content, quietly productive and enjoying whatever perks they throw your way.
But if you're problematic in some way, you're only worth so much effort.
And worse, if whatever is wrong with you threatens to spread to the rest of the herd (eloquent expressions of shared discontent, organizing, even being a bit of a natural leader, if they're paranoid), well, who employs things that threaten them?
At the same time, HR does regularly help employees avail themselves of resources (communications with health insurers, 401k providers, etc.). So in that sense, they are "there" for employees.
As far as I can tell, HR does a few things:
1. promote the idea that the company is a great place at which to work (market the company to potential hires, tell current employees about all the great perks, downplay negatives or ignore them)
2. answer most general questions of current employees (benefits)
3. document statements given to and taken from employees (hiring them, firing them, workplace allegations, rules violations, etc.)
Most of it is designed to protect the company but some of it is sometimes the only way to get something if you're an employee. If you ask: "where should I go to set up my 401k?" or some variation, you are pointed to HR.
So they help employees, but it’s to a large degree self-serving (even if the HR person himself does not realize it — it’s why he doesn’t get in trouble for wasting time on it). But when it becomes actively detrimental to the company, always assume HR will make the decision in favor of the company.
Treating HR as generally hostile is also a bad idea — the assumption of hostility is often met with the same, and now both you and HR are acting slowly, carefully and inefficiently — but never assume they’ll always be your friends. They’re generally friendly, and they may even be considered friends, but ultimately their loyalty is not to you.
The same is true of really anyone in the company — your boss, your coworkers, your attorneys, etc. Their loyalties are always to themselves, and their families first (by which job preservation is a very strong incentive), and maybe you fall in line somewhere.
I think we agree on the role played by HR. You need to be aware they serve the organization first (as do we all). I just wanted to point out that in the day-to-day, they often provide real benefits to employees, which may be self-serving but there’s no rule that self-serving behavior can’t be mutually beneficial.
And to be honest I don't see myself doing anything different than that as well. It's going to be very unlikely I am picking a fight with my employer whatever you are coming to me with.
There would be a few factors driving this
1) The stress of not having a job is extreme, and represents a state that people try to avoid thinking about too much.
2) It is, in fact, true for many people, and we want to think of ourselves as people that it's true for, instead of one of the "suckers" that it's not true for.
One should never rely on a statement from an employer that isn't in writing. Furthermore, even if it is in writing, if it says "discretionary bonus," you should consider that a big fat ZERO. If it says "possible," "maybe," "if," etc. you should consider it to never happen (if it's for your benefit, otherwise, assume it definitely will happen).
Only after the above can you reasonably compare offers between prospective employers or value your current job.
HR is trained to hire you at the lowest price and say the most that they can without making fraudulent claims.
Additionally, if you are a current employee, and you EVER speak to HR, walk in with a pen and notepad and take long long notes and do not hesitate to ask someone to pause while you document. Treat it as a legal deposition. They are not your friends, they are trained to extract or give statements that protect the firm (not you).
It's unfortunately a pretty stark reality but it's business. It's even worse if the people involved are your friends - because it will hurt more if you aren't protected or have the wrong expectation. There's a reason that the expression, "never go into business with your family," is a thing.