I'm assuming that you mean that you are turning the screen off not powering down the phone. This is probably the power optimization pausing the music.
- Open phone settings
- Click on Apps
- Click on the music app that you are using
- Click on Battery
- Ensure that "Optimize battery usage" is set to "Not optimized".