In the dossier, he's described as a "dormant asset". Being "dormant" means that at a certain point he must have pro-actively worked for the Thalmor.
I think that the "certain point" at which he was not dormant was when he was their prisoner and they had tortured him to the point where they could actually get information out of him. He wasn't dormant when he was talking to them and providing information, but I see no reason to believe that he continued to do so once he was out of their clutches. Obviously they misled him with regard to how "helpful" he was to them, leading him to believe that his failure to withstand the torture had given them something that was instrumental in their success in taking the Imperial City. They probably hoped that this would make him feel that his ties to the Empire were irreparably severed, that once having "turned" it was impossible to go back and that he had made an irrevocable choice between them and the Empire. "You were disloyal to them, therefore now you can be loyal to us or have no friends at all." That sort of thing.
But I think Ulfric found a third option, which in his mind, at least, is loyalty to Skyrim
as Skyrim, not Skyrim as an Imperial province that must be defended and protected out of allegiance to the Empire.
And I agree with the previous poster that reading the Thalmor dossier, at least after I read it again closely and thought about what it was really saying, made him seem like a much more tragic figure deserving of my sympathy and understanding. WIth my Stormcloak characters I always RP that when I return to Windhelm after finding the dossier I give it to him so he knows that I know and don't hold it against him that he once failed to hold it together as a young man undergoing such a horrible ordeal. Generally by that time my PC as been in more than one Thalmor dungeon, so... yeah. I know what they're capable of and I'm not gonna second guess anybody's inability to withstand that.
Even Captain freakin' Picard admitted that when the Cardassians* were torturing him, he got to a point where he would've told them
anything to make it stop.

*May not actually have been Cardassians, since it's been a while since I've seen that. But whoever they were, they were
not nice people.