We don't really know for sure, what caused the craters, because we didn't observe them form. However scientists do have some theories.
The most common theory is that they were formed by meteor impacts. This is backed by the fact that there are more craters on the back side of the moon (i.e. the side facing away from the Earth), and that the craters match impact crater models made on Earth.
Another theory, is that when the moon formed, it had active vulcanism, and that the craters were actually volcanic calderas, and that would explain the lava flows that made the "Seas" on the moon (darker regions). This is also backed by the presence of active vulcanism on Jupiter's moon Io. However, the craters on the moon don't match the topography that would be expected of volcanoes.
The final theory, is the "Creationist" theory that the moon was formed with the craters, per the account of Genesis, but this theory is largely disregarded due to its "religious" elements.