Fortunately the Music app includes a handy feature that can spring into action whenever your device's storage space runs low, and automatically offload songs you haven't played for a while in order to make space for newer ones.
It's called Optimized Storage, and here's how you can enable it.
- Launch the Settings app on your iPhone or iPad.
- Scroll down to the apps list and select Music.
- Under Downloads, tap Optimized Storage.
- Toggle the Optimized Storage switch to the "on" position so that it shows green.
- Choose a minimum storage amount that you want to keep for music before downloaded songs start being removed from your device.