Here's why:
* The Moon orbits the Earth.
* The Earth orbits the Sun.
The Moon's orbit around the Earth is not perfectly aligned with the Earth's orbit around the Sun. Because of this, the Moon's position relative to the Sun changes as both the Moon and Earth move.
It takes about 29.53 days for the Moon to complete one full cycle of phases (from new moon to full moon and back to new moon), which is the time it takes for the Moon to return to the same position relative to the Sun.