Two topics not discussed are leaks and rationalization.
Say someone's getting fired for not being the right race, or being a woman in a mans field, or not being a bro, or not going out drinking with the boys enough after work, she wouldn't date the boss, or being too old, or too gay, or too jewish, or whatever. "Sorry its a budget thing combined with different direction of company and best of luck to you" is legally extremely safe. Happens ALL the time. But if the boss has some deep personal conversation and it leaks out that he doesn't like most black people but he hired you anyway so its clearly not race, he doth protest too much, or how it doesn't matter that she wouldn't date him despite him asking her a couple times it really was something else... Or the rationalization thing, where lets face it, he was fired because he is gay and the boss is a republican, if the boss is smart enough not to leak that topic, but sufficiently dumb enough, in a long personal conversation out will come ridiculous rationalizations about the guys LoC or bug report / fix rates or attendance as a distractor for the boss to avoid talking about homophobia, unfortunately the rationalized metrics can actually be measured and open the company to wrongful termination lawsuits. "Your honor he said the only reason was my attendance wasn't very good, but my documents prove it was the best in the office, note the only day I was gone was a scheduled vacation day for the pride parade and he's out of the office continually attending fund raisers for anti-gay marriage republican candidates" etc etc. Usually that kind of stuff is settled expensively out of court with non-disparagement clauses so future employees can't avoid predatory bosses, which is another problem.
You can pretty much assume if "they" won't tell you why you're fired, and you can't obviously figure it out, then it was some illegal thing like above and they're smart enough not to provide lawsuit fodder on a platter.
Ya gotta realize that half of management is by definition below median, and that half of the population can create very expensive lawsuits.