I think what you’re describing is happening because the JS is already loaded on page load. From my experience, if you have inline scripts that have never been saved via the Theme Editor they won’t run until saving.
In your example, the JS could have been saved on a different page with that same section/block and so it was already in the compiled file that Shopify creates.