It’s actually both. The dictator comes after the realization that Socialism doesn’t work. So in order to enforce Socialism, because it conflicts with normal human pursuit of self interest and advancement, the dictatorship follows
Some countries, like Sweden, do eventually legislate socialism away or vote it away. But more often than not it does lead to dictatorship