Then they should not do that job.
People who work in HR do useful things. I have leaned on "people operations" support in most companies I've worked for, they do recruitment and policies on employee behavior and performance management and a bunch of other things. This is all valuable work. I'm glad it's not what I do for work, but it would be a much suckier world if nobody chose to do this work.
But they are also asked by company leadership to be the buffer, to be the messenger that gets "shot", when bad or even necessary but incredibly painful decisions are made. It's part of the expectations of the people who hire them, that they'll do that.
So what do you suggest? Do all the other useful stuff, but then when asked to be that buffer in these shitty moments, they should quit and find a new job? What should they say when asked why they quit? Is it ethical to lie about it, or do they tell a prospective new employer that there is an expected part of the role they're applying for that they are not willing to do?
Or is your suggestion something better? Like perhaps there could be a professional guild for HR professionals, and they could have a code of ethics that makes it clear that this is not something they will do. I think that would be pretty great! But that would be a much bigger and entirely different project that individuals quitting in protest.
Or perhaps your suggestion is, actually, that there should be nobody working in HR, that it is not a useful function. In that case, no, that's wrong, I've worked with many smart technically inclined people who think this, and I've worked at companies that are led by people who believe this, and it sucks.
I'm all for shifting the expectation of who has the responsibility for delivering the news of shitty decisions onto the management that made the decisions, but there has to be some theory of the case for how to get there from here.