I didn’t knew that the Moon has quakes. Most of the quakes come from the tidal forces, the gravitational pull from Earth of Moon’s surface. This pull makes the layer of Moon dilate and contract and cause quakes which propagate easily through the entire satellite as the Moon does not have a liquid layer to absorb those mechanical waves.
Marsquakes seem to be generated by magma inside Mars, but not much can be told about these, just the fact that they do exists, because huge boulders get moved around from time to time. Wind couldn’t do that, so marsquakes are believed to be the reason.