Earthquake causes shaking of the ground. So a building resting on it will experience motion at its base. From Newton's First Law of Motion, even though the base of the building moves with the ground, the roof has a tendency to stay in its original position. But since the walls and columns are connected to it, they drag the roof along with them.