Stalin used the collectivization of Soviet agriculture as a way of breaking the back of peasant resistance to his rule. He knew that the peasants, who formed the overwhelming majority of the Soviet population, were deeply hostile to the Communist regime. Their aims were completely at odds with those of their new masters in Moscow. For one thing, they wanted more land for themselves and the ability to cultivate it as they saw fit. They also wanted to buy and sell their produce on the open market.
But Stalin would not allow any of this. He wanted all aspects of Soviet life to be tightly controlled by the ruling Communist Party, including agricultural production. Since the agricultural sector of the economy had massive strategic significance, he was all the more determined to ensure that it came under his control.
Collectivization was the means he devised to achieve this objective. By forcing Soviet farmers to join collective farms, Stalin hoped to ensure that agricultural output was used to further his overriding economic policy of industrialization. Much of the agricultural produce from the new collective farms—most notably grain—was to be exported in order to raise much-needed foreign currency that would pay for the rapid industrialization of the USSR.
Collectivization was a monumental failure, which led to a massive decline in agricultural output as well as widespread famine among the peasant population. In the long-term, however, it allowed Stalin to control the peasantry and eliminate another potential source of opposition to his regime.
The collectivization of agriculture was used in much the same way by Mao in Communist China. Not long after the Communists came to power in 1949, they embarked upon a radical program of land reform, taking land from the hated landlord class and giving it to the peasants who'd previously worked on it. During this period, it's estimated that as many as 1 million landlords were executed by the Communists. Once they were out of the way, their land was distributed among the common peasantry, the very people who'd formed the backbone of support for the Chinese Communist Party (CCP) during their years of struggle.
Although the land reform program was heralded as a measure that would give freedom to the peasants, in actual fact it consolidated the power of the CCP. The peasants had only been given their land at the behest of the Party, and the Party could therefore just as easily take it away from them. Which they did.
For after the initial spurt of land reform, the drive for increased industrialization meant that land which had been distributed among the peasants in private plots was now commandeered by the state and concentrated into vast collective farms. As in the Soviet Union under Stalin, Mao's regime saw collectivization of agriculture as a crucial step on the road to modernization, with farms producing more food to support the projected army of industrial workers that the regime hoped to create.
At the same time, the CCP realized that, whatever the stated aims of the policy, collectivization was a useful means of keeping the peasants firmly under state control. As the Chinese peasantry formed the overwhelming majority of the population it was all the more necessary for the government to ensure that they did not step out of line. The Communists were all too aware that any opposition to the regime was likely to emanate from rural areas, and so the peasantry needed to be organized into discrete political units, such as collective farms, in order to head off any potential uprisings.