How to fix mogrify / convert “attempt to perform an operation not allowed by the security policy `PDF'”

When you see an error message while running mogrify or convert such as

mogrify-im6.q16: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/426.

this is due to a bug in previous Ghostscript versions.

See this StackOverflow post on how to fix it.