Why does the moon orbit the earth and not the sun instead?
The moon does orbit the sun but it also orbits the earth.  But your assertion that the earth's gravity is weaker than the sun's is not universally true.  If the sun's gravitational pull were greater than the earth's HERE on the earth, the sun would literally suck everything not attached to the earth's surface into itself.  Clearly that's not happening.
Remember that Newton's Law of Gravitation says that the force is inversely proportional to the SQUARE of the distance.  So while the sun does have a stronger gravitational pull, the distance that both we and the moon are at makes the earth's field dominate.