DaveC426913 said:
cmb, glue a penny to the ceiling. By your logic, gravity would pull on the penny regardless of the penny's internal forces, and eventually stretch the penny toward the floor.
No. Gravity is acting on the penny's lower surface but we do not witness the penny stretching to the floor as gravity works on it (yes, even if we wait a very, very long time). The penny's internal forces easily overcome gravity. It does not mean gravity does not apply, it simply means it is overwhelmed.
I don't entirely like this analogy, though, because it is gravity that is both holding galaxies together and affecting how quickly they move away from one another.
The basic, basic picture here is that overall, you have a big universe that is, on large scales, smooth and uniform. The mutual gravity of all of the matter in the universe wants to slow this expansion down.
Now, in slightly more detail, some bits of the universe are more dense than other bits. It isn't
entirely smooth. This means that some bits, having more matter, are better at slowing down the (local) expansion than other bits. If it turns out that there is enough local matter, then the mutual gravity is enough to not only slow down the local expansion, but cause the local system to collapse in on itself, forming a gravitationally-bound system. The overall, large-scale expansion still goes on, but the local gravity is enough to stop it in certain parts of the universe.
Of course, as I mentioned earlier, dark energy changes this somewhat as it adds an extra repulsive force, and this does have an impact on how big things can be and still end up bound together. But this effect is small on the scale of galaxy clusters and even smaller on anything smaller than a galaxy cluster.