To understand this, you need to know a few things about electrons. It may help you in understanding situations like this.
Electrons Like Electrons of Opposite Spin
Yes, you read that right; electrons which have an opposite spin are attracted to each other. This is better explained using quantum mechanics, and this post is too limited to fully explain why. In any case, this opposite-spin attraction is a reason why rubbed things exchange electrons; some atoms are more "greedy" than the others, so they take on extra electrons when in close proximity to less "greedy" atoms. This is due to unpaired electrons in the valence shell attracting other electrons to fill the shell. These shells get filled in spite of the fact that it gives the whole atom a negative charge.
Electrons Like Lower Energy Levels
Electrons also like going to lower energy levels. That is, if a neighboring atom has a lower energy level available, or even if there is a lower energy available within the same atom, the electrons will try to go there. There can be, however, a cost involved for electrons switching which atom they belong to. This is called an "energy barrier," and you can think of it like a toll. If an electron doesn't have enough energy to pay the toll, it can't go to a lower energy level.
For example, an electron in situation #1 experiences being attracted to another atom (due to opposite-spin attraction). The energy barrier is effectively paid by the opposite-spin attraction. Then the electron begins feeling the force of the atoms it left (due to charge difference). The electron, however, does not have the energy to get back to the old atom. This could be because you moved the metal spheres away from the rubbed item, or the energy barrier has changed, or simply because the atom the electron is in is simply "too greedy" to let go.
Grounds Act Like Big Electron Reservoirs
Grounds are simply big electron reservoirs. If a charged item gets in contact with a ground, it transfers electrons until both things have evenly distributed their electrons, assuming no energy barriers stop them.
For example, if a metal ball is missing a mol of electrons, and you bring it into contact with a ground with a 100 billion mols of electrons, the electrons will go back and forth until the electrons are evenly distributed between the two. Even if a mol of electrons went to the charged item, it doesn't really make a difference to the ground. The charge differences get diluted enough that they are practically gone.
It should be noted, though, that when I say "contact" here, I mean that the energy barrier is small enough that the electrons (generally) have enough energy to get through. So you can be in physical contact with a rubber ball, but the electrical contact isn't there.
Back to the Two Situations
In situation number 1, you act as a ground because you have enough electrons available to transfer between the two charged things. The dilute charges (or missing charges) get spread out enough that there is no noticeable charge. The electrons don't even themselves out because, until you touch it, the energy barrier to do that is too high.
In situation number 2, you are a charge carrier, and the doorknob is your ground. The carpet has a bad enough "connection" with the ground that charges don't easily come up and neutralize unbalances until some time after you've shuffled through. More scientifically speaking, the energy barrier for the electrons that would balance out the potential difference is too high. The door knob, however, is much more electrically "connected," so you get a nice zap as the electrons scramble for a lower energy level (in the doorknob/door/earth). Once again, the energy barrier is low enough to go the doorknob, but not to the carpet/earth.
In Short: Electrons can only flow if they overcome an energy barrier. If the energy barrier is too high, they can't go. If the energy barrier is lowered, they can go.