I think Google also optimizes for lack of a better term, ‘engagement’.
So, even if an ad has a higher margin, it may be better to ‘slot in’ a lower margin ad that would get more aggregate clicks, so the net profit is higher.
Poor example:
Ad is $10 per click but is only clicked once per month versus an ad that is $1 and clicked 20 times per month.