You'd get a howl of argument from me on that one, if only because it's not your right as DM to tell me how to play my character.
The DM isn't telling you how to play your character. The DM is making a
suggestion as to how you might want to change the way you play your character,
as an alternative to no longer being invited to their game.
If my character doesn't fit in with the party it's up to the party - in character! - to deal with, either by accommodating him or throwing her out or leaving him behind or killing her outright. Or just making things such that my character's best option is to leave.
Regardless, it's still my character and does NOT become an NPC; and I can still play it in the background even if it does leave the party (e.g. secretly follows the party anyway).
That would be the DM's call.
If the DM OKed the character getting booted because the way that you were playing them was disruptive to the game on the OOC level, they are likely to not allow that option.
The social contract covers, and ends at, how I fit in with the other players at the table. The characters in the game, however, aren't beholden to any such meta-contract.
Most games that I'm aware of are no-PVP from session zero/social contract. The DM has a remit to work against the characters, which is going to have the potential to kill them, but still might try to avoid specific issues that would cause the player to no longer enjoy playing that character.
Because characters are played by the players, their behaviour will be constrained by the meta-contract that constrains the players.
And right there you've taken in-character actions to an out-of-character argument, which wrecks the whole thing.
Deal with it in character, and laugh about it at the table.
Please bear in mind that this is
not about harmless inter-party shenanigans, or agreed-upon PVP in a PVP game.
Its not about something the player can just laugh off.
It might be an action that strikes too close to an issue that the player has had to deal with. It might be a potentially long-term change to something that the player regards as a core part of the identity of a well-loved character.
This is about doing something to the character
that actively upsets the player.
As in
you are
choosing for your character to do something to their character
that you know will upset the player.
As in you are choosing to upset the player. - Who presumably was a friend.