How does my iPhone choose which music app to start when I pair with the Bluetooth unit in my car? I'd like it to automatically start Spotify every time, but sometimes it starts playing from the Music app, even if I've used Spotify earlier that day.
Delete the iOS music app and then play a song with any other music app, such as Spotify. This other music app will now be the default music app that will be automatically started when you pair your iPhone with the Bluetooth unit in your car, even after restarting your iPhone. As stated in the original question, this will not always be the case if the iOS music app is installed on the iPhone.
This technique is also detailed in an answer to a similar question.
I always thought that it was the last app which was used to play audio which was chosen for playback when you connect to bluetooth, and my experience until now supports that.
But, we know that IOS can relentlessly kill apps running in background if there is a critical RAM (memory) bottleneck in the system.
Could it be the case that while you were browsing the web and doing other things, there has been a memory (RAM) bottleneck in the system and spotify was killed while it was in the background? If that was the case, when you connect to the bluetooth and the car stereo commanded iphone to play something, since Spotify was already dead, the phone probably defaulted to its own music player.
What model is your iphone? If it has a model which has less than 4GB of RAM, this case could be more probable, depending on what you have did on that couple of hours while browsing the web.
Next time when you experience that, I recommend taking your phone and trying to open Spotify. If spotify launches from the scratch (full screen spotify logo is shown while starting), that supports my thesis. If it just opens as you closed it before (i.e. no full screen spotify logo while starging the app), that means that it wasn't killed by IOS, and my thesis is wrong, so something else should be going on.