Hi require_support,
Thanks for posting your question about the Music app. I'm happy to see how I can help out.
If you're finding that iTunes Store purchases are being deleted from the device, it sounds like storage is a factor to look at. This resource, How to check the storage on your iPhone, iPad, and iPod touch, may account for what's happening:
If your device is low on storage, it automatically frees up space while installing an app, updating iOS or iPadOS, downloading music, recording videos, and more.
To make more storage available, your device can remove some of your items, like streamed music and videos, files in iCloud Drive, and parts of apps that aren't needed. It also removes temporary files and clears the cache on your device. But your device only removes items that can be downloaded again or that aren't needed anymore."
If that's the case, you may want to look at the suggestions in the link I posted above to see if you can free up some space overall on your device.
Regarding "Optimize Storage," are you an Apple Music subscriber? Based on the information here, it looks that function is specific to use of the Apple Music subscription service: Add music to iPhone and listen offline
I hope this helps get you started. Take care.