I think it’s likely that he made some kind of deal with Cersei. Exactly what deal, we’ll find out when Bran tells everyone.
Next season will start with the Snow etc. blocked from returning to Winterfell by the Undead, while the Dothraki & Unsullied armies marching the King’s road. So we’ll probably see a Battle of Winterfell which I assume falls, with some kind of rescue to save the Starks. I say that because they laboured over the decision to fly to Winterfell, so the lack of Dragons at Winterfell will be a thing.
They also laboured over the population of King’s Landing, so an attack on King’s Landing will possibly be a thing too, but maybe after the retreating armies of the Targaryens meet the Golden Company and Lannister Armies. I expect it’s around then that Cersei’s betrayal will be revealed and Tyrion will be compromised.
As for Tyrion’s survival, there is a taboo on being a kinslayer in Westeros, maybe that was a factor? or maybe he’ll get a trial by combat at some point in the future and we’ll see the Hound vs. The Mountain.