Music app suddenly switches to speakers
This sounds like a serious issue with the iPhone 7 lightning-to-audio adapter. 

You're going to have to diagnose the issue:

Try buying a new adapter to see if that fixes the issue, and also try using the native lightning earpods to see if those consistently work right. If a new adapter fixes it or if the issue can't be reproduced while listening with lightning earpods, it's the audio adapter's fault. If the issue isn't fixed by the new adapter but is fixed with the lightning earpods, you probably have some headphones that aren't compatible with the iPhone 7 (for whatever reason). If all else fails, just talk to apple at https://getsupport.apple.com and try to get yourself a hardware replacement.