When you plug up a phone to a USB port, there are "options" for how the phone appears to the port as a "device." In android, you can change that in developer options. It can appear as simply a USB memory device like a thumb drive, or a media player (MTP) like an ipod, or it can be "charge only" etc. To some extent, this is automatic but it can go wonky and manually changing it can fix it back.
I am sure the iphone is the same way, but I am not sure how you access those settings.
Even if the settings are correct, it can take some time for your head unit to "read" the contents of whatever device you plug up, even if it's just a thumb drive with no directory structure. When you plug up a phone, it has a complex directory structure and it can take some time to scan and read the music files, if that is what you are aiming to play. And sometimes that glitches and doesn't happen or happen in a reasonable time.
So, if it works intermittently, a) give it some time and b) try unplugging and replugging and c) dig around to find the settings for how it appears once plugged into a USB port.
Diggging around, it seems that IOS started locking out USB access automatically if your phone hasn't been unlocked for an hour to avoid USB hacking.
How to Access Controls for USB Restricted Mode in iOS 12
That right there might explain it.