The whole We play a game so you have to cooperate together even if role-play wise it makes no sense is a bad practice, May-be not at the point you'll leave the table but definitely a serious sign that the table doesn't function properly.
Luckily, there is a very easy fix Do a session zero, and build a coherent party ab initio, it include in game reason for the party to work together, coherent goals (because when player A wants to abolish the reign of the emperor, and player B wants to defend the emperor you'll have a PvP fight within 3 session) and a meta discussion to have a pallet of skills matching the party's goal (At least in more epic game where you don't want to feel powerless). Almost every RPG published in the last 10-15 years contains an extensive session zero guide and tons of tips to build a relevant party.
If someone wants to play a law priest in a pirate campaign or any other character not fitting the campaign theme or opposing other PCs, it's perfectly OK to tell the no. Obviously if everybody is aligned on some PvP and betrayal the answer may be different, but it's again something to address in session zero.