When is it appropriate to contest a GM?

Ι am struggling to find helpful information about when it is appropriate for a player to challenge a GM’s decision.

There was a recent question which triggered this "old chestnut" for me: Does a Swarmkeeper lose their swarm if they die?

If a GM decides that a Swarmkeeper Ranger permanently loses his/her swarm when they die for the fist time and there is not a way to recover the swarm, then -in my books- the GM has gone too far with their "it’s my way or the highway" attitude. And, this is not in the spirit of the game.

I’ve had other experiences similar to this, where the GM removed the soul of my PC -because he didn’t like it- and, when my PC "died", he said "sorry unresurrectable" by any means. Yet, everyone else’s characters were resurrected many, many times.

On another occasion a GM specifically targeted one of the other player’s PC by a mob with CR that wa enough to wipe-out a five-person L15 party, yet the player’s PC was only one level 10 character. The reasoning, the mindless mobs had a thing for Gnomes! The player was really upset and it ruined the session.

I have been myself a GM for donkeys’ years… and I allow my players to contest certain things. …I may even backtrack at times if what they explained makes good sense or there is not a RAW/RAI rule to fall back on. It might even become a house rule after that at the table.

It would help to have some guidance on this. D&D is a game that is meant to be fun for the GM and players alike. Yes, with fun dramatic moments, but these examples are not in the spirit of "fun". In none of the examples I gave did any of the other players think those rulings were fair.

So, is there any guidance in the D&D literature about how to resolve these sort of disputes, other than "The GM always has the final say!"?

I would appreciate answers from any of the D&D editions and/or concrete examples from experienced GMs.