Really, the answer to your question is simply: Plate Tectonics. Read below for details.
It all comes down to stress and strain from the interaction of different plates, chiefly at the boundaries. It is not 'the plates rubbing together' as many people say; or at least that's a very simplistic view.
Plate tectonics causes stress on the continents and oceans, all over the surface of the earth. In some places, the stress is very small (usually within the plates). Elsewhere, the stress is high, usually where the plates meet each other. Since each plate moves, when two come in contact, the stress each other. They can push on each other and cause compressional stress, they can pull with extensional stress, and they can slide past or shear each other with tensional stress.
Faulting, causing earthquakes, comes from the fact that this stress is building up all the time, but rocks and continents are strong materials. Just like hitting a rock with a small hammer, you do put stress on it, but a small amount. It would take a sledgehammer to put enough strain (effects and accumulation of stress) to build up and cause breakage. In the earth, the area around an active fault builds up strain from the stress of plate tectonics. Most faults become locked, because of this strength, and thus can not release their strain. Away from the fault, the stress produces very small and slow movement of the rock masses as a whole. Eventually, the strain is too much and the rest of the plate has moved too far and the fault releases the strain build-up all at once in a big stress release called an earthquake. This is called the elastic rebound theory, and it explains most (but not all) movements.
This is why an earthquake's size is relative to the fault size. The bigger the fault, the bigger the strain build up, and the bigger the release in an earthquake. Subduction zones and collision zones, where large portions of plates actually can rub together as a whole, have the really big earthquakes, like the 2004 Sumatra earthquake. In other plate boundaries, the entire plate boundary does not act together, so the faults become spread out and many faults take up the strain from the tectonic stress, like with the San Andreas Fault in California (it only takes up ~3/4 of the stress between the plates).
Earthquakes are really tricky things; there is still so much we need to learn. As of now, there is no way to predict them, but we can say where the danger is highest and about how long between events.