The gallery block only allows you to add links to the images, and then only to the attachment page or the media file. So that’s no good.
The gallery block itself is in a
<figure> element, so wrapping that in an
<a> tag is semantically incorrect, and the block editor throws up errors.
How about putting the gallery inside a group block and then wrapping that in an
<a> tag? The group block is a
<div> so wrapping that in an anchor is OK in HTML5. But using the page code editor still throws up errors.
The answer is to add one custom html block before the group block and another after it, the first containing
<a href="the-url"> and the second containing
</a>. Works perfectly…