Will he break any laws by saying that (assuming the actual truth
cannot be found out)?
The statement made outside the courtroom is not itself perjury, since it is not made under oath. But that doesn't mean that there wouldn't be legal consequences.
It would be powerful evidence in a perjury prosecution (surely enough for a conviction even standing alone long after the trial is over but within the statute of limitations for perjury in the jurisdiction from the date of the sworn statement, if any), and would be a waiver of 5th Amendment rights against self-incrimination, generally, in the perjury case.
It might also be strong evidence (enough to convict standing alone) in a timely obstruction of justice prosecution. This statute of limitations could also run from the date of the sworn statement, or from the date of a false unsworn statement that caused a conviction to be reopened.
If the statement made in court was favorable to the prosecution, it might bring these charges after the conviction in the underlying case is final. But, the out of court statement would probably be grounds for the party benefitting from the original statement to seek a mistrial or to have a judgment set aside if the verdict or judgment is consistent with the sworn statement.
If the out of court statement was made before the trial was over, the witness could be recalled and the out of court statement could be used to impeach the in court statement.
It might constitute a probation or parole violation.
If the witness were testifying pursuant to a cooperation agreement, the out of court statement would probably breach the deal and deny the witness the benefit of the cooperation deal.
The out of court statement might constitute contempt of court if made while the proceeding in which the statement was made was still pending.
Depending on the nature of the statement, the out of court statement might constitute defamation for which some one whose reputation was tarnished might sue for money damages. (There is immunity from civil liability for in court statements.)
It would violate the ethical rules of many professions. For example, an attorney would probably be disbarred for doing that. Arguably, in this situation, the statute of limitations could run from the later unsworn statement date rather than the date of the sworn statement.
If the witness is a state or federal government employee, this could lead to impeachment proceedings, in the state legislature, or Congress, respectively.
The aftermath of the Lewinsky Scandal (link below) involving Bill Clinton touches on many of these possibilities:
Further investigation led to charges of perjury and to the impeachment
of President Clinton in 1998 by the U.S. House of Representatives. He
was subsequently acquitted on all impeachment charges of perjury and
obstruction of justice in a 21-day Senate trial. Clinton was held in
civil contempt of court by Judge Susan Webber Wright for giving
misleading testimony in the Paula Jones case regarding Lewinsky and
was also fined $90,000 by Wright. His license to practice law was
suspended in Arkansas for five years; shortly thereafter, he was
disbarred from presenting cases in front of the United States Supreme
Court.
Easier and Harder Cases
The easier cases are those where it is undeniably clear from other evidence that the witness lied under oath, and the out of court statement merely puts the cherry on top of an already solid perjury case.
The hard cases aren't the cases where "the actual truth cannot be found out". Instead, the hard cases are the cases where there is strong evidence that the statement made in court, under oath was true.
For example, suppose Ted Cruz is asked in court: "Were you the Zodiac killer?" (A crime ridiculously attributed to him despite the fact that it is something that happened when he was a small child who live many hundreds of miles away.) And he says, "No" in court, but then leaves the courtroom and says in a press conference on the court house steps: "I am the Zodiac killer, I lied about that under oath in court today."
Similarly, suppose that a DNA test on a certain blue dress shows a perfect match to President Bill Clinton and Bill Clinton says under oath in court, that the substance tested came from him on a certain day, in a certain place, when a certain person was wearing it, in a certain way (also confirmed by a witness and surveillance video). Then, he leaves the courtroom and says in a press conference on the court house steps: "Someone else was the source of that genetic material. I never met that person, and I was in Kenya on the day alleged and I've never set foot in the White House. I lied about all of this under oath in court today."
In these cases, there is no plausible way to make an obstruction of justice or perjury charge stick, or to upset a verdict or judgment consistent with the truthful sworn statement.
Contempt of court is still possible, as would professional ethics violations, but other consequences would be less obvious, because the act would come across more as absurd instead of something that genuinely confounds the truth.
The legal consequences associated with the conduct in the original post are mostly aimed at sanctioning genuinely fraudulent conduct. Our legal system is more confused about how to respond to lies so blatant that they only amount to feeble and ineffectual gaslighting that no reasonable person familiar with the circumstances would believe (but that might incite crazy conspiracy theory thinking supporters). The harder case would lie in the uncanny valley between a bad joke and a pathetically weak attempt to mislead people, even though the law is clear about how to deal with clear sarcasm and convincing attempts to lie that can't be clearly proven or disproven with other evidence.