If Jupiter's gravity is what kept the asteroid belt from forming a planet, then why didn't the sun's gravity keep the inner planets from forming?
why didn't the sun's gravity keep the inner planets from forming?
The short answer is, the asteroid belt orbits the sun, it doesn't orbit Jupiter, and you shouldn't expect the same effect with 2 different relations.
The sun is the gravitational object that the Asteroid belt orbits. Jupiter is not and it has a stabilizing effect on the material that orbits around it. Jupiter has a (mostly) destabilizing effect on nearby material that orbits around the sun, though there is some stability with orbital resonance and trojan points. The reason why that is gets a little bit mathy, but I'll cover the basics.
When a solar system forms, probably out of a combination of strong solar wind from a supernova and a dense enough gas cloud, most of the solar-system material forms the young sun and maybe 2%-4% remains in orbit and over time, spirals and flattens out into a disk. (see cool video)
The sun's gravity stabilizes that disk. There's no reason for it to disburse it, though the young and usually strong solar wind can blast it and clear out the closer regions of smaller particles and any ices.
Jupiter is entirely different. Jupiter and other planets which form inteh disk, tends to eat everything in their path. That's one of the definitions of a planet. It clears out it's orbital area. These planets on their own would remain in orbit around the sun, but they can interact over time with each other. Pretty much anything in Jupiter's path, once Jupiter gets large enough, either gets eaten or gets thrown into a very different orbit, either further our or closer in.
The asteroid belt is (as Suhrid Mulay points out) a relatively low density region of space that doesn't have enough mass to coalesce into it's own planet, but it might not have always been that low density and that's probably only part of the reason. The other part of the reason is the proximity of Jupiter which tends to disrupt anything that orbits too close to it and Jupiter may have at one point, moved in quite a bit closer to Mars before moving back out. Tossing much of the material in that region far away.
Planets don't do well forming too close to other planets because they will gravitationally disturb each other. A planet the size of Jupiter had pretty significant reach when it comes to disturbing other planets and planet formation.
During the early days of the solar system there was a high abundance of matter in the early solar system. Easily enough to form the planets and a lot of matter to spare. Also during the initial stages of formation of the solar system matter was distributed very densely when compared to what the density is today. At that point there were lots of asteroids and other small bodies very close together therefore at that stage local gravitational fields played a major role in formation of the planets. rather than the sun
As for the asteroid belt. It cannot form into a planet because the matter density is very low and its proximity to the giant Jupiter makes it very vulnerable to its gravitational field. The gravitational fields between the asteroids are simply not enough to coalesce them together into a planet due to very large distances (between the asteroids) involved