It takes advantage of a physical phenomenon called jamming transition. When particles (like coffee grounds) are so densely packed that they can no longer slide past each other, they behave like a solid. When they're loosely packed, they behave like a liquid. Coffee is actually a pretty good analogue for this phenomenon — when you buy those mini vacuum-packed bags of ground coffee, they're hard as rocks; all the air has been sucked out, and the coffee grounds can't move past each other. Open the bag and introduce some air, and they behave like loose particles again.