Implementing a modal(lightbox) for all images in all post-gallery posts

This W3Schools page shows how to create a lightbox with HTML, CSS and vanilla JS only:
https://www.w3schools.com/howto/howto_js_lightbox.asp

If you have lots of photos on a page, you may want to remove the code related to the “thumbnail image controls” that they use in this example. But, other than that, I think their example shows what you want to do.

Another solution might be to use a jQuery-based library like Fancybox:
http://fancyapps.com/fancybox/3/