Same reason the planets do.
They’re basically all going around the Sun with us, just at different speeds and distances.
Asteroids are basically mini-planets; small lumps of rocks (anywhere up to a thousand kilometres across) orbiting the Sun, minding their own business, but not big enough to collapse into a full planet and “clear” the space around them.
Comets tend to have fairly squished/elliptical orbits, which means they can kind of [swing by](https://en.wikipedia.org/wiki/File:Comet_Kohoutek_orbit_p391.svg) and then zoom off into the outer Solar System for a long time before coming back again.
It’s actually really hard for things to “escape” the Solar System; they have to be going very fast – if not they’ll end up looping back in again eventually. Kind of like throwing something up in the air – unless you throw it very hard it will fall back down again.
There are also an awful lot of these things. [This little animation](https://en.wikipedia.org/wiki/File:PIA22419-Neowise-1stFourYearsDataFromDec2013-20180420.gif) shows the things detected by Nasa’s “Near-Earth Object Wide-field Survey Explorer” programme, from 2014-2018. The blue rings are the orbits of the inner planets (the paler blue one is us, Earth). Each dot represents an asteroid or comet – the green ones are asteroids that pass near the Earth at some point in their orbit, and the yellow dots are comets that tend to be more far-flung and just zoom by (but will come back eventually).
While space is ever expanding, it is only expanding on truly huge scales – at scales between clusters of galaxies. Asteroids and comets are things within the Solar system, so much, much more local.
Latest Answers