Which really should not work in court, but it seems it has so far.It actually hasn't worked for them in court at all. They've always had to disclose the data under penalty of sanction (meaning fines, and possible adverse rulings). In most of the cases, the jury decided that the driver was at fault and that Musk's statements were just meaningless marketing fluff.
In the Miami case, if Tesla hadn't turned over the data the judge was prepared to issue an instruction to the jury that they could use Tesla's failure to provide evidence as per se evidence of Tesla's liability (meaning, that Tesla would have to present an affirmatively prove the opposite, which would necessarily entail providing the evidence it was attempting to keep hidden). Judges will frequently also prevent parties found to have hidden evidence from presenting defenses on the matters affected by the undisclosed evidence. In extreme cases, they simply rule against that party on the merits, and the case becomes about the size of damages.
In the Miami case, several of the jurors said that learning that Tesla had tried to hide the evidence from the crash was a big factor in finding Tesla liable, the reasoning being that Tesla wouldn't have tried to hide the evidence if they weren't liable.