This is a play on two different meanings of work.
In socialism doesn't work, the word work is used to refer to something that functions or succeeds. The Macmillan Dictionary definition reads
[intransitive] to operate in a satisfactory way
The new telephone system seems to be working perfectly.
This pen doesn’t work.
My brain’s not working very well today.
The they in they don't work either refers to people who support socialism, and work is in the sense of
[intransitive] to have a job, usually one that you are paid to do
Dominic works part-time.
In other words, to paraphrase, the only people who think socialism is a functional system are people who do not have jobs. The statement is not meant to be factual, but rather might be repeated by someone on the political right to cast aspersion wryly on people who support socialism as being disconnected from the discipline of work: students and academicians, the unemployable, celebrities and the idle rich, the lazy, and so forth.