Example: https://ibb.co/fHv6ThK
And removing from the ads would mean the App Store gets less money from the app's creator (assuming it's pay for impressions rather than pay for clicks)
Which is to say, it's part of the protection racket.
First of all, if company X pays to have an ad published when a search query includes a particular set of terms then they definitely expect the ad to be present more or less prominently, not hidden away where no one can see it, to make a difference, otherwise why bother paying for it.
Now, stop for a second and put yourself in Google's shoes... is there a financially-wise alternative to what they are doing? Where would you put the ad?
You're most certainly not going to push all ads down to the 2nd page and restrict the 1st page to only real/organic/whatever you want to call them results because many users are never going to bother navigating to that 2nd page before clicking out on any of the earlier results.
It also doesn't make sense to order identical results:
link to company X website (organic)
link to company X website (ad)
instead of the other way around because again, the probability that a user will click on the first link is going to be (considerably?) higher than the second one, so it's going to be a less efficient way to make money.
In the end, the search engine survives because of advertisements. If they didn't optimise ad placement in this way (and other less obvious ways) and the ad revenue decreases or completely dries up then the company goes bust, so in my opinion it makes 100% business sense to make said decisions.
So it's not a matter of whether search engines are smart enough to detect that identical scenario, it's whether it conflicts with their monetisation strategies... It would be a really stupid idea (and make for a short-lived company) to make decisions that shrink your ad revenue if that's your main (or only) source of income.
Some people will also click on the ad result instead of the actual search result, resulting in Apple/Google earning some money for the click.