While Kollontai's survival might seem like an oversight on the part of Stalin, there were a number of reasons that all intervened to keep her alive.
Firstly, although Kollontai was present within both the Workers Opposition faction and the earlier events of 1917, she was far from a powerful figure in either period. Kollontai was very forceful in her opinions, but this really did not carry much weight with her largely male colleagues. With very few exceptions, the upper echelons of the Bolsheviks and the Soviet state were very much a male affair irrespective of factions. While many within the USSR's power structure would give lip service to gender equality and progressive policies on the family, there was little interest in these areas. Bolshevik women like Kollontai often found themselves shunted off to minor postings very low on the pecking order like the Zhenotdel or writing Bolshevik family law. Kollontai's outspoken opinions on free love and sexual liberation further marginalized her within the nascent Soviet system. When push came to shove, most of the Bolshevik men were fairly socially conservative when it came to sexual matters and gender. For example, when the German KPD activist Klara Zetkin appealed to Lenin for permission to organize Hamburg's female prostitutes, Lenin responded with a scathing critique. Lenin argued that prior attention the KPD paid to prostitution was a tactical decision to underscore the moral hypocrisies of bourgeois society. The Soviet leader then shot down any connection between Communism and increased sexual liberalization:
It seems to me that these flourishing sexual theories, which are mainly hypothetical, and often quite arbitrary hypotheses, arise from the personal need to justify personal abnormality or hypertrophy in sexual life before bourgeois morality, and to entreat its patience. This masked respect for bourgeois morality seems to me just as repulsive as poking about in sexual matters. However wild and revolutionary this behavior may be, it is really quite bourgeois. It is, mainly, a hobby of the intellectuals and of the sections nearest to them. There is no place for it in the party, in the class conscious, fighting proletariat.
Lenin wrote similarly sharp rebukes to Kollontai over her pamphlets such as "Make way for the Winged Eros," which predicted greater female sexual agency under the auspices of Communism.
What this meant as Stalin outmaneuvered his political rivals was that Kollontai was really not that much of a political threat. She possessed little in the way of a following and, unlike Trotsky or Zinovieiv, she did not command agencies that Stalin and other Bolsheviks considered to be very important. This also quarantined her to a degree during the Great Purges because she did not have much occupational proximity to those purged. Even as a diplomat, she had little direct connections with her male colleagues whom often received more important postings. Molotov and other leaders in the foreign service did not see her as a threat to be neutralized.
Kollontai's personality also played a role in her survival. She was much more pliant and willing to publicly tow the dominant political line. When her colleagues shunted her off to the diplomatic service in the 1920s, she proved to be a very agreeable servitor to the state. Her loyalty also dovetailed with her gender as she became one of the public faces of Soviet progressiveness as an ambassador and diplomat. Kollontai herself was very much an agent of her own survival here. When the Zinoviev-Trotsky bloc tried to claim she was on their side in October 1926, she personally went to Stalin to assure him of her loyalty. Her diaries and other accounts from Stalin's entourage also speak of her using flattery and other wiles to get on the dictator's good side. One of the interesting facets of Kollontai's diary report on her October 1926 meeting was that she egged Stalin on to give a performance on topics she knew Stalin thought he was an expert on such as factionalism or Trotsky's mistakes. Kollontai also knew to hedge her bets and wrote articles in public praising the new course in the Soviet state. As a diplomat, she never broke from Moscow's line, even if it meant engaging in double-talk and reversals.
Kollontai's diaries do though show she was afraid that the "wheel of history" would fall on her. Beatrice Farnsworth has found a persistent tone of ambivalence over the Stalin turn and remorse for those destroyed by the purges. The diaries could have been a rope that hanged her, but luck intervened. The NKVD had found and photographed her diaries in the early 1940s, but the man tasked with reading them and reporting to Beria, Elisei T. Sinitsyn, was an admirer of Kollontai. He told Kollontai in 1944 that he reported back to Beria that the diaries contained nothing of interest.
Sinitsyn's favor to Kollontai shows the degree to which happenstance sometimes played a role in death and survival under Stalinism. Having made the right impression or contact (or the wrong one!) could be a matter of life and death. Kollontai gamed the system to survive, often at the price of having her own ideas on sex and the family sidelined.
Sources
Farnsworth, Beatrice. "Conversing with Stalin, surviving the terror: The diaries of Aleksandra Kollontai and the internal life of politics." Slavic Review 69, no. 4 (2010): 944-970.
Healey, Dan. Homosexual desire in Revolutionary Russia: the regulation of sexual and gender dissent. Chicago: University of Chicago Press, 2001.
Hoffmann, David Lloyd. Stalinist Values: The Cultural Norms of Soviet Modernity, 1917-1941. Ithaca, N.Y.: Cornell University Press, 2003.
Wood, Elizabeth A. The Baba and the Comrade: Gender and Politics in Revolutionary Russia. Bloomington: Indiana University Press, 1997.