It is actually an ad provided by the game you were playing. They use an Ad Service that promotes the advertisement. You will find the most common Ad Services companies are owned by Google or Meta and they provide ads for many games. Apple does not provide the ads you see in the apps.
The way it works is that it adds a sound file to play to your Music Player like any app can do. The name of the sound is Scanning Your Device and it plays 2 beeps. It is an attempt to get you to purchase some kind of anti-virus software that you do not need.