All I know for sure is that the head uses a magnet to stay on. My guess is that there is some type of magnet inside the sphere to attract a magnet inside of the head. The head then has rollers so that it can roll along the top of the sphere. Of course the inside magnet would have to be movable so that you could make BB-8 do fun head moves.

But is that the only way to make it work? No, of course not. Check out these cool instructions for building a different kind of BB-8. This other version has the motor only in the head and sits on top of a plain ball. By moving the head, you can also exert a torque on the ball to make it move. It’s an interesting idea (even if the head for this version is huge).