This is a significant challenge. It's one reason that I like to use page attachments for images that are page specific. If a page is archived or deleted, the image is archived or deleted with it.
In your situation, it sounds like you're looking for a way to clean up the media library, based on what images are needed to support the published pages. There are a few solutions, but either option requires tedious manual work, or custom code.
You could use a site crawler like Screaming Frog to crawl your site for images. This would give you a list of all images used by published pages. You could then compare this list to the list of images in your media library, to identify which ones are used by published pages. Beware, you may have a mix of direct media URLs and permanent URLs. Either way, you'll be able to identify the media files, whether by path, or by guid.
You could create a tool that crawls your content tree to identify media files that are in use. This will be feasible if your content is in page type fields. It will be very difficult if you have content in editable text web parts and widgets. The tool would have to know the fields in every type that may have a image url in it. Typically, this will be rich text fields and text fields using the "URL selector" or "Media selection" control. The tool would have to scan all nodes in the content tree, looking for the use of a media file, to determine whether or not an image is used by a published page. This would be tough, but feasible. Unless you needed some automated tasks to happen regularly, I'd opt for a solution similar to the first one.