The law is the Prison Act 1952 which gives the secretary of state powers to restrict prisoner communications. https://www.legislation.gov.uk/ukpga/1952/52
This is enacted through Rule 34(3) of the Prison Rules 1999 (SI 1999/728):
"A prisoner shall not be permitted to communicate with any person outside the prison, or such person with him, except with the leave of the Secretary of State or as a privilege under rule 8."
The operational guidance that spells out the media-specific restrictions is PSI 37/2010 – Prisoners' Access to the Media, which prohibits prisoners from:
Making statements likely to cause unnecessary distress to victims
Making gratuitous reference to victims
Bypassing the rules by having a third party (e.g., a family member) publish their comments
Edit: added second half regarding third party bypassing.