When its body dries out, it weakens. So it wraps a membrane around itself for protection while it spits poison.
From its Pokedex entry for BW2. If it can spot poison, it can also spit out some non toxic protein chains that act like a membrane. Similar to a Spewpa or a Spinarak but different in function. They're bugs, they do some gross stuff. That's nature, I suppose.
Besides, it's based partly on snails, which are known to produce slime to move about. If Accelgor evolved to create slime that hardens to protect its body, that's not such a large jump of faith to accept as a similar process.