The Duke of Sussex and the publisher of The Sun newspaper will keep the contents of their settlement confidential, a High Court judge has said.