I see the issue is happening because the class is not added to the IMG tag, so Smush can’t target it.
Couldn’t you enhance this feature so that it targets child elements?
For example:
<div id="header-element">
<img src="/wp-content/themes/mycooltheme/assets/img/headerimage.png><img>
<h1>This is my awesome header!</h1>
</div>
And then exclude #header-element
This would be for example very helpful for themes with a widget area at the top of the page.
This seems to be some incompatibility with another plugin that I have, not sure, which one is to blame. The SA Slides backend seems to be using the Bootstrap 5 file from the other plugin which is then throwing the error. When I deactivate the other plugin, the problem disappears.