Shouldn't some stars behave as black holes?
The true answer lies in General Relativity, but we can make a simple Newtonian argument.
From the outside, a uniform sphere attracts test masses exactly as if all of its mass was concentrated in the center (part of the famous Shell theorem).
Gravitational attraction also increases the closer you are to the source of gravitation, but if you go inside the sphere, some of the mass of the sphere will form a shell surrounding you, hence you will experience no gravitational attraction from it, again because of the Shell theorem. This is because while the near side of the shell is pulling you towards it, so is the far side, and the forces cancel out, and the only gravitational forces remaining are from the smaller sphere in front of you.
Once you get near the center of the sphere, you will experience almost no gravitational pull at all, as pretty much all of the mass is pulling you radially away from the center.
This means that if you can get very close to the center of the sphere without going inside the sphere, you will experience much stronger gravitational attraction, as there is no exterior shell of mass to compensate the center of mass attraction. Hence, density plays a role: a relatively small mass concentrated in a very small radius will allow you to get incredibly close to the center and experience incredible gravitational forces, while if the same mass occupies a larger space, to get very close to the center you will have to get inside the mass, and some of the attraction will cancel out.
The conclusion is that a small mass can be a black hole if it is concentrated inside a small enough radius. The largest such radius is called the Schwarzschild radius. As a matter of fact our own Sun would be a black hole if it had a radius of less than $3$ km and the same mass, and the Earth would be a black hole if it had a radius of less than $9$ mm and the same mass.
Stars generate a great deal of energy through fusion at the core. Basically the more massive a star is, the more pressure the core is under (due to the star's own gravity) and the more energy it can generate (somewhat simplified).
That energy of course radiates outward and heats everything outside the core making it a something like a pressure cooker, with heat creating pressure and the outer regions of the star being kept in place by it's own gravity. Stars would collapse into more dense objects (like white dwarfs and neutron stars and black holes) if this outward heat driven pressure did not exist.
Black holes are created when the fusion process can no longer generate enough energy to produce that pressure to prevent collapse and the star is massive enough so that it's gravitational field can compress itself so far it becomes dense enough to be a black hole.
Roughly speaking, for a star to become a black hole, its physical radius has to become smaller than its Schwarzschild radius. So even the Earth could be a black hole if it shrinks to below 9 milimiters. It is not precise to say that a black hole depends on the density of the object, since a Schwarzschild metric is a vacuum solution of Einstein's field equations.