Here is the explanation from https://www.yahoo.com/tech/this-self-assembling-chair-from-mit-may-be-the-111860644734.html
It works like this: Researchers plopped six separate objects into a tub of water. Inside each of these objects is one or more specially designed magnets, installed at key connection points. Each magnet is made to be attracted to only its perfect match, so there’s no chance that the chair will accidentally put itself together upside down.
Think of it like Saturday night at your local bar. As the water in the tank tosses the pieces around, they bump together until each connection point is eventually united with its intended partner. Of course, both the construction of each piece and the environment it is placed in have a huge effect on the process. Researchers must consider the size, weight, and construction of each block, not to mention the turbulent force and volume of water in the tank that the whole bundle is placed in.