When an earthquake applies a force to the building, then the pendulum exerts a force in the opposite direction of motion.
The following diagram shows the force applied by the pendulum and earthquake,
The force applied by the pendulum balances the earthquake's force so that the net force becomes zero on the building.
Hence, the building is saved.