Not all Earthquakes are shallow, but the most powerful are. This is because at depth, where the rock is hotter, the rocks can more easily pass each other and dissipate pressure by ductile flow.
At shallower depths, where the rock is cool, are plates try to pass each other, they are rigid and so fracture or release pressure elastically in a single event. This is an Earthquake.