According to Soviet leader Vladimir Lenin, it is the first principle of socialism. The phrase is mentioned in his 1917 work, State and Revolution (chapter 5, section 3). Through this slogan Lenin explains that in a socialist society (which Karl Marx termed "the first phase of communism") only productive individuals would be allowed access to the articles of consumption.
This is not really directed at lazy or unproductive workers, but rather the bourgeoisie. Since Marxists hold that the bourgeoisie lives off the labor of others, they are seen to be incapable of producing anything. In Marxism, the bourgeoisie would either starve to death (literally and metaphorically) or begin to work beside the proletariat in the factories and farms.
The principle would not apply to those who could not work, such as the elderly or the lame. These groups would have a right to society's products because they were not at fault for their condition. The elderly, furthermore had worked during their youth, and so could not be denied life’s basic necessities.