When a player joins a cup, the system records his clan/communities/country and these groups remain till the end of the cup.
A possible harm is that, if a player quit his clan at finals and join another, the system would give his new clan the gold medal, while he played the entire cup as his old clan.
So your groups remains as what it was till the end of that specific cup.
@maciej, there was a bug in challenges, but at the time I fixed it, I had to calculate all records from the start and since system hadn't record your groups (now it does), it had to get your clan again and by that time you were in o2 if I'm not wrong.