The foreground app is always going to have control over any audio that is playing, whether that is from the app or if it is going to allow play through audio from another source. It can pause/resume or even prevent audio from playing from another source. There is no ranking of audio that is determined by iOS, it is the sole discretion of the app you are currently using. If your current foreground app is not resuming your previous background music, that is either by design of the developer or an oversight on the developers part if they have not resumed your audio after they told the system to pause it for the content they want to play.
From the Developers perspective, this is done using the AVAudioSession framework within their app. The default behavior is to pause background audio when the app chooses to play something, but they can certainly configure the AVAudioSession to perform any way they wish. A game that plays ads is making the choice to have the ad content play instead of your background audio for monetary reasons and they are sending the Pause command to the System for your background music.
AVAudioSession | Apple Developer Documentation
In addition to the 2 previous solutions of not using that particular app, or choosing an in-app purchase option to eliminate the ads, I should also have added a 3rd option to contact the developer as they are certainly capable of resuming your background music after it has been paused, if they wish. You are having to manually start your background music again, because the foreground app is not doing it for you. If a Developer wants to allow this, they must notify the system to return your previous audio source:
Let other apps know when your app finishes playing temporary audio. If your app can temporarily interrupt the audio of other apps, be sure to flag your audio session in a way that lets other apps know when they can resume. For developer guidance, see notifyOthersOnDeactivation.
Playing audio | Apple Developer Documentation
Sorry to get into the weeds on how developers use these API's, but the point is that the foreground app has total control of the audio playing while you are using that app.