Because it captured two asteroids from the asteroid belt.
Mars' orbit is very close to the main asteroid belt so it has seen a rather violent history of cosmic bombardments. But also quite a few chances to capture one or a few of these asteroids in orbit. This is probably exactly what happened. Because of its proximity to the asteroid belt, its gravity managed to capture two asteroids a few million years ago and now they orbit Mars.So,Phobos and Deimos are likely captured asteroids.