The court makes orders
It’s not just that different law firms with different class-actions might initiate multiple lawsuits in a single jurisdiction - they might initiate them in multiple jurisdictions.
Different jurisdictions handle this differently but ultimately courts have the power to decide how and if a case is brought. This includes deciding whether cases should be joined and, if so, who the lead law firm will be. It also includes cooperating with courts in other jurisdictions although this is more easily accomplished when the jurisdictions happen to be in the same country. For example, all state, territory, and Federal courts in australia have the power to cooperate with each other written into their enabling legislation. So, if a case is brought in say new-south-wales and victoria, the Victorian court may adopt the judgement of the New South Wales court except where Victorian law differs (or vice-versa). Here is a practice note from the Supreme Court of Victoria explaining the process.
Depending on jurisdiction, class action lawsuits might be “opt-in” or “opt-out” - I think most ore opt=out but I haven’t done a comprehensive survey. In either case, the law firm representing the class has a duty to identify and communicate with the class members. In an “opt-in” jurisdiction, anyone who does not opt-in does not benefit from the outcome of the lawsuit has their rights preserved. Similarly, in opt-out jurisdictions, anyone who actively opts-out is in the same position.