For eight years, the government has refused to disclose letters written by the prince to ministers, and the newspaper has fought the decision in the courts.

The prince, who has distinctive handwriting – his letters have been dubbed the “black spider memos” – has been accused of writing to ministers to air his views on government policy.

A freedom of information tribunal ruled in a landmark decision last year that 27 letters between the prince and the government over a seven-month period between 2004 and 2005 could not be withheld and could be published in the public interest.

However, Dominic Grieve, the attorney-general, later issued a certificate to override the tribunal’s decision arguing publication of the “particularly frank” letters reflecting the prince’s “most deeply held personal views and beliefs” would mean there was a risk the heir to the throne would not be seen to be politically neutral.

The Guardian sought to challenge the lawfulness of the Attorney-General’s decision and quash the certificate.

Giving his ruling, Lord Justice Davis said the Attorney-General “had reasonable grounds for certifying as he did”.