He left Disney after being passed over for CEO. Although (assuming that Microsoft or a comparable company buys TikTok) he would likely stay on as its head, with potential to rise within should he do a good job, Mayer is one of the very few people who's already been in that exact spot (or higher; Disney might have a smaller market cap than Microsoft, but in every other way they are equals in their global reach and ambition), so to speak, so it's understandable that he wouldn't want to go through it again.
That said, surely his contract has provisions for a payout should his company gets acquired. Wouldn't leaving before any transaction close void that?