Tommen has to die before Cersei. The prophecy said she would see all her kids die and it's been 2/3 true so far. My guess is that it would happen right before Daenerys storms Westeros since an unclaimed throne would throw the whole continent into chaos. Who will claim it from the Lannister/Barentheon side will be tough to pin down, but try this theory on for size:
1. Margery gets herself pregnant
2. Tommen is killed
3. Margery gives birth and then dies (or Cersei has her killed)
4. Cersei tries to install herself as Queen Regent for her grandson
That results in perhaps a 3-way war (or even 4-way depending on what Littlefinger is up to) between Lannister/Tyrell vs. Jon "Snow" & The North vs. Daenerys(/Greyjoy? /Martell?). Eventually the Wall comes down and they all have to put things aside to put fire to those icy walkers. Not sure who ends up alive at the end of that but I would assume one of those claims sits the throne in the end. Hell, I would not be disappointed if the whole thing throws a curveball at us and the smurfing Night King sits on that damn throne.