The same reason the "Democratic People's Republic of (North) Korea" is a democratic republic... It wasn't. There was a time when socialism really seemed like the way forward, tempering free enterprise with thoughtful regulation and investing workers in the means of production. So non-socialists like the Nazis and Communists called themselves socialist to appeal to the political moderates of the interwar period. In the modern day, anyone who equates socialism with either Nazi-brand Fascism or Soviet-brand Communism is a political propagandist, usually affiliated with right-wing US interests.