I don’t think that is true. I think the purpose is usually to prevent the parties from trying their case in public.
Ideally the public and the court should reach the same decision. Another reason I see is to protect the witnesses. Has their safety been compromised?