Garak was always on the side of Cardassia, it just so happens, for a while, The Federation's goals lined up with "His Cardassia's" goals. I don't think that he believed he was working against Cardassia when opposing Dominion rule by aligning with The Federation, I believe he felt he was working for Cardassia, just as Damar eventually did.