During the reign of Joseph Stalin, huge numbers of people were incarcerated in the prison camps known as the Gulag. The Gulag served a political purpose and an economic purpose.
Politically, the Gulag was meant to isolate people who might pose a political threat to Stalin and/or to the communist system. The communist system, as implemented in the Soviet Union, was one which could afford no dissent. The regime attempted to be totalitarian and to ensure that no one harbored any dissident views. The Gulag was one main way of ensuring this. All those who had dissenting views, or who were suspected of them, were incarcerated. At times, it did not really matter if the people incarcerated truly were dissenters. The presence of the Gulag and the ease with which anyone could be sent there, was frightening enough to suppress dissent even if some of the inmates were not really dissenters.
Economically, the Gulag supplied labor for some of the huge projects that Stalin implemented. Stalin wanted to industrialize and modernize the Soviet Union very rapidly. One was to do this was through forced labor that could help make up for a lack of machinery and other technology. The Gulag provided this labor, helping to push the country forward. It is not clear that this was the best way to achieve this, but it was the method that Stalin chose.