Since Punk Hazard, Trafalgar Law has been an ally of the Straw Hats in One Piece. In the real world, it may have occurred between 2013 and 2020, and it continues to this day.
Law's main assignment was to defeat Kaido, but his major goal was to defeat Doflamingo, which he did from Dressrosa.
1. Will Law split up with Luffy if Kaido loses?
Although TrafalgarLaw had joined Luffy in his fight against Kaido, his original goal was Doflamingo. At the time, the law intended to either hunt Doflamingo or have the marines hunt him (when Doflamingo withdrew from the Shichibukai).
Kaido's rage is directed at Doflamingo or the marines if this occurs. But that didn't happen; instead, Law and Luffy brought down Doflamingo, and Kaido's rage is now directed against him and Luffy.
Law has become closer to Luffy as a result of the events in Dressrosa. So, whatever happens, he won't end the alliance before Kaido loses. Even if Law doesn't want to, his life may be in danger.
2. If Law survives the Wano arc, his function is effectively gone
Law's quest was actually fulfilled once he defeated Doflamingo. This was just additional for Kaido's protection and respect for the bond he had formed with Luffy.
Unless there are any more shocks, Law's duty should be fulfilled after Kaido likewise loses. If Law survives the Wano arc, he will end his relationship with the Straw Hats. There's no need for him to continue traveling with Luffy; Law and the Hearts must go on their own journeys.
3. Farewell to a friend who is no longer a stranger to Luffy
But isn't Law a well-known One Piece character because he's been associated with the Straw Hats for seven years in real life? Is he really going to break up with her in that way?
Previously, Oda had no trouble separating Luffy's group from Vivi's. Despite the fact that she was already a member of the Straw Hats. If the party at Wano is the time for the two gangs to split up, they will. It's possible that the situation is similar to Luffy and Bege's group, who split up after the plot at Cake Island ended.
4. That doesn't rule out the possibility of Law returning to assist Luffy in the future
Dressrosa, and later Wano, Law, got up close and personal with the Straw Hats. If he is no longer allied with Luffy, it does not follow that they will never cooperate again. I suppose the situation is analogous to the Straw Hat Great Fleet. They are free to go on adventures for the time being, but when Luffy needs them, everyone will show up.
Will Law become a member of the Straw Hat Fleet? Perhaps, perhaps not. But, after everything they've been through, if Luffy is confronted with a threat such as Blackbeard or the World Government and requires assistance, Law can return even if he doesn't join the Fleet.
This is Littleowh's take on Law's departure from the Straw Hats following the conclusion of the Wano arc.