How does a cloth-melting drug not affect hair? It's literally keratin in both cases.
Not necessarily. Plant based fibres (which underwear was usually made of) are mostly cellulose. Besides, one could argue that wool clothing will have lost most of its oils from washing, while (healthy) hair still has them. As fat keeps liquids away and limits the effects of acids, that might play a role.
Finally, if we're talking magic, hair connected to the body is usually considered "alive", while cut hair is considered "dead". Slimes, for example, are often characterized as eating "dead" matter, be it cadavres, wilted plants or clothes, while leaving the living alone.