Craters on the Moon were caused by impacts from rocks or comets from space that smashed into the surface of the Moon. The impact was so powerful that it pulverized the ground, creating what we call regolith, and sprayed it out to form ejecta rays. The Moon has no atmosphere, and so even a tiny rock can create a crater. Once something hits the Moon, that event becomes frozen in time, and almost nothing can remove marks on its surface once they are made. The Moon has almost no erosion because it has no wind, weather, or plants. The Moon has not had tectonics for billions of years, which means that the surface of the Moon is recycled much less than the surface of the Earth, and there is a lot more time for craters to form and stay put. The Moon once had large volcanic flows way in the past that did cover up many of the bigger earlier impacts, but it has been without volcanism for around three billion years. Nowadays, the Moon is still being hit by objects, albeit mostly tiny ones, and as there is no atmosphere on the Moon, there is no gas to help burn up these rocks from space and stop them smashing into the Moon.