In Season 7, Episode 2, when Jaime tries to convert Tarly to the Lannister cause, Tarly responds something like this:
I swore an oath to House Tyrell. I’ve known Olenna since
I was a child.
It's not far-fetched to derive from this that up until then he simply always followed whatever allegiance house Tyrell had. So even your premise for the war of the five kings is a bit misguided. He did not declare directly for Renly, rather he was as always a loyal bannerman of house Tyrell, which supported Renly. So it makes sense that after the war, up until the explosion of the great sept of Baelor he supported Tommen Baratheon and thus indirectly the Lannisters because they were in allegiance with the Tyrells. In the aftermath of that explosions he likely still supports the Tyrells but before any real action happens Jaime persuades him to change sides.