Why did people wear gas masks in World War 2?

They didn't. There was a great fear that poison gas would be used against civillian population centres or on the battlefield. It did not happen in WW2.