How to edit a deleted image gallery?

WordPress galleries are not true “objects”, they are just a kind of one time macro. There is no real DB of them, just a shortcode in the content and once you deleted it, there is no gallery any more (except for in the old revisions).

The code you referenced is a relic of the old days in which by default a gallery would have been all the images associated with a post, but those old days are long gone and unless you insert manually, the current way is to add the ids of the images to the shortcode and once the shortcode is deleted…. puff you can’t restore it from any other place except for backup.