An object’s inertia tends to resist any change in its state of rest or motion. If a carpet is beaten with a stick then the carpet begins to move. But, the particles of dust are trying to resist their state of rest. The concept can be explained based on Newton’s first law of motion.
When the carpet is beaten with a stick, the stick exerts a force on the carpet which sets it in motion. The inertia of the dust particles residing on the carpet resists the change in the motion of the carpet. Therefore, the forward motion of the carpet exerts a backward force on the dust particles, setting them in motion in the opposite direction. This is why the dust comes out of the carpet when beaten.