pineapple has an enzyme in it which breaks down protein. Some people use it as a tendersising marinade on meat. Hair is made up of the protein Keratin so presumably, especially when combined with the acids in a buns tummies, it acts on the hair and breaks it up in to more manageable chunks or disolves it completely.
Enzymes can be destroyed through heat which is why there may be less in canned pinnaple. If the pinapple was air dried then the enzyme would still be there......they can be dried which is why you get biological washing powder.