If You’re Pinned by an Opponent says
When an opponent has pinned you, you are held immobile (but not helpless) for 1 round.… On your turn, you can try to escape the pin by making an opposed grapple check in place of an attack. You can make an Escape Artist check in place of your grapple check if you want, but this requires a standard action. If you win, you escape the pin, but you’re still grappling. (PH 157)
(Emphasis mine; I'll get back to it.) So, unlike the grapple rules of Pathfinder wherein a creature must typically take a standard action on each of its turns to maintain a grapple it initiated, in D&D 3.5e once a creature's successfully initiated a grapple a creature doesn't have to do anything to maintain that grapple. Every creatures' options are limited in the same way while they're in the grapple, and no creature need maintain it.
This means even if an ally joins his friend in a grapple against a mutual foe and the ally pins that mutual foe, no one—not the pinner, not the pinned, and not even the I-really-don't-want-to-be-here dude—escapes the grapple for free.
Yeah, this is complicated. Here's a walkthrough.
Round 1
Abe possesses a base attack bonus of +6 and the feat Improved Grapple. He makes a full attack and, on his first attack, make a grapple attempt against Bob. Abe succeeds on the touch attack, succeeds on the grapple check, deals to Bob his unarmed strike damage, and enters Bob's space. Instead of his second attack, Abe makes an opposed grapple check to pin Bob and wins.
Bob, on his turn, tries to escape from Abe's pin. Bob fails.
Chris joins the grapple as Bob's ally. Chris has a base attack bonus of +6 and doesn't have the feat Improved Grapple, but her touch attack against Abe is automatically successful and doesn't provoke attacks of opportunity because Abe is already in the grapple. She wins the opposed grapple check against Abe, enters Abe's space (which is also currently Bob's space), and deals to Abe her unarmed strike damage. Instead of her second attack, Chris makes an opposed grapple check to pin Abe and wins. Now Abe and Bob are pinned, Abe by Chris and Bob by Abe!
Round 2
The duration of Abe's 1-round pinned effect on Bob ends. Bob is no longer pinned, yet Bob is still in the grapple. However, Abe can only attempt to escape Chris's pin. Abe fails to escape Chris's pin.
Now, here's the potential controversy, and the part you probably won't like: technically, for Bob to escape the grapple typically Bob must still either take an attack to win an opposed grapple check against Bob or take a standard action to make a successful Escape Artist skill check against Abe's grapple check result, Abe's immobility not preventing Abe from being—essentially—the defender during opposed grapple checks. Imagine Bob still in the midst of a (TV Tropes warning!) Big Ball of Violence: Bob must nonetheless exit that big ball of violence somehow, and typically the only avenues available for exiting it are beating Abe in an opposed grapple check or that Escape Artist skill check. Abe being pinned? That doesn't really help Bob get out of the grapple. Poor Bob's essentially caught in the crossfire.
(The Rules Compendium clarifies that immobile here means stationary and that means that a pinned creature has an effective Dexterity score of 0 (61), and even the Player's Handbook assesses an additional -4 penalty to the pinned creature's AC against melee attacks (151). This means Bob might actually be better off just suffering the -4 penalty and against Bob making an attack with a light weapon, a natural weapon, or—or, y'know, not—an unarmed strike.)
(Also, yes, I do find it hard to justify with a narrative a pinned creature maintaining a grapple with two foes: "And then Chris jumps in and gets Abe in a suplex, but Abe just keeps on holding on to Bob's shirt, somehow not letting go!" or whatever. That is a little weird and does seem a little forced. It's why I recommend than an ally that wants to free a buddy from a mutual foe's grapple to do so from outside the grapple either by stabbing the foe until it stops grappling or by making a bull rush against the foe (or the ally!) as described in answer to this question.)
Then the duration of Chris's 1-round pinned effect on Abe ends. Chris can do whatever she wants, limited, of course, by the grapple, including attempting to pin for 1 round—again—the kind-of-apparently-outclassed Abe.
"For 1 round…?"
The pinned condition is theoretically temporary. That is, the pinning creature each round must re-establish its pin versus its foe or else the pin ends, yet establishing that pin takes only an attack and limits the pinning creature's options. (Although the pinning creature still has more options than the pinned creature!) This means pinning a foe then thumping on that foe is totally a thing for 1 round… then, on its next turn, the pinning creature must take an attack to make an opposed grapple check to pin and win to pin the foe again for 1 round. Unless vastly outclassed—like by most of a d20—eventually a pinned creature should have a round of not-pinned. Eventually.