the answer

Typically there are two ways these work. One is to have a very tiny cantilever, like a diving board, only millionths of a centimeter long. When the device moves in some direction, the "diving board" flexes a tiny amount one way or another. Circuitry on the device detects changes in resistance or some other quantity (capacitance, conductance, etc.) caused by this flexing. There can be up to three such "diving boards", one for each direction of motion in 3D space.

The second (and more modern) way of doing this is to have a microscopic bubble of hot air created by a heating element on a microchip. This bubble is then tracked with heat sensing circuitry as it moves in three dimensions as a result of gross motion of the chip. This newer technique is more sensitive, and since it has no moving parts is more robust and cheaper to make.