The earth’s crust is divided into several plates which are essentially floating about on the liquid mantle. It is inevitable for these plates to move apart and towards each other, resulting in collisions and friction. For instance, if two tectonic plates come together, the first collision might cause what are called ‘foreshocks’, these can be seen as signs ahead of an earthquake.
When these plates continue to grind against each other, they can become locked at the boundaries. This causes a build-up of stress and tension, much like in a spring or elastic thread. When the stress reaches its breaking point and the plates finally slide over, a large amount of force is also released, causing shockwaves and shaking the crust.
If you study the world map with depictions of all major earthquakes till now, you will see that the majority of them are focused around tectonic plate boundaries.
Apart from earthquakes caused by tectonic plates, we also have volcanic earthquakes, which are not as common as the former, but can be equally destructive. Volcanic earthquakes are a result of volcanic explosions, and are generally limited to round a 30 kilometer radius around the volcano.
Volcanoes which have acidic lava are much more likely to explode. This is because acidic lava cools down very rapidly after being exposed and can essentially block the volcano and its release points. This means that the heat, steam and lava inside cannot come out and the pressure starts building up. When the pressure eventually exceeds all limits, it results in an explosion, unblocking the volcano or creating a new exit. The force of this explosion can cause seismic waves and consequently earthquakes.
Since all an earthquake needs is pressure build-up and sudden release of force, human activity can also trigger small and large quakes. This is most commonly the case with missile testing and large explosions, but these incidents are not typically classified as earthquakes.