Your leader and HR make the decision. And they don't care if it was with malice or not. I found an issue turned it in and got terminated. THey all admitted it was their fault but they fired me because I had been their a long time and did not want to give me severance.
I was high performing, long term great reviews etc but it did not matter I found an issue in an HR system and HR wanted me to go and I did.
Luckily I make enough money that employment attorneys were willing to take the case. In the end it cost them way more than had they laid me off. Do not trust, document EVERYTHING and go talk to an attorney.
HR is not your friend. Your manager is not your friend. I found an issue that had been a fubar before and the team asked ME to help fix it and I was gone. The best part was that the Ahole who made the decision had to sign off on my settlement.