Hair is made up of the root and the shaft. The shaft, which is what we see on top of our heads, is biologically dead and made up of three parts: the medulla (innermost region), the cortex (middle layer) and the cuticle (outer covering).
The cortex is made up of keratin proteins which have a high percentage of negatively charged amino acids. The cuticle consists of several flat, thin cells laid out like roof tiles. As the hair shaft is damaged these cells become loose or fall off, leaving the cortex, and the negatively charged amino acids, exposed. These rough cells get caught on neighbouring hairs and tangle up.
Detangling shampoo contains anionic (negatively charged) ingredients which remove dirt, natural oils and positive charges from the hair. It also contains detangling/conditioning cationic (positively charged) ingredients, which are attracted to the exposed negatively charged amino acids on the cortex. The cationic ingredients are also hydrophobic (repel water) so are not washed out easily, leaving your hair coated with a thin film. This film closes the gaps left by damaged cuticle cells making it easier to comb and detangle.
Agnes Becker, science museum