First of all, not all hairsprays work. The chemicals in hairspray that causes the bonding is "VA/Crotonates Copolymer", it is also called "vinyl acetate/crotonic acid copolymer". Most commonly known as PVA, which is also a filament used as water soluble support material. This is a synthetic polymer created from monomers.
When heated to a certain temperature this ingredient becomes sticky, this makes the filament stick to the plate. It is the double bonded Oxygen molecule that makes this happen. This is not only present in chemicals you put onto the bed, but also the chemistry of certain bed materials. Quoting our own Ryan Carlyle from this thread, A replacement for Aquanet Hair Spray?? Wolfbite by Airwolf:
Most of the popular build surfaces have very similar underlying chemistry. That's because they all rely on diffusion welding for adhesion. The molecular chains at the interface slightly dissolve into each other.
Gluestick active ingredient - http://en.wikipedia.org/wiki/Polyvinylpyrrolidone
Aquanet and liquid PVA glue active ingredient - http://en.wikipedia.org/wiki/Polyvinyl_acetate
If you're familiar with organic chemistry, what you see here is an identical polyvinyl backbone chain, and functional groups that both have a ketone/ester double-bonded oxygen adjacent to a space-filling component. (The space-filling component probably decreases adhesion so the print can be released.) And guess what? Permanent build plate surfaces rely on the same underlying chemistry:
Lexan also has exposed double-bonded oxygen on a polymer backbone: http://en.wikipedia.org/wiki/Polycarbonate
Kapton also has exposed double-bonded oxygen on a polymer backbone: http://en.wikipedia.org/wiki/Kapton
Acrylic also has exposed double-bonded oxygen on a polymer backbone: http://en.wikipedia.org/wiki/Poly(methyl_methacrylate)
PET also has exposed double-bonded oxygen on a polymer backbone: http://en.wikipedia.org/wiki/Polyethylene_terephthalate
Now, if you look at some common solvents for filaments, what do you often see? Double-bonded oxygen on small molecules. Here's ethyl acetate (dissolves PLA) and acetone (dissolves ABS):
These molecules are still diffusing into the filament polymer, but they're so small and mobile that they are able to completely liquefy and dissolve the plastic.
Isn't chemistry great?