There are no hard rules about this.
An "encounter" in D&D 3.5 is a loosely defined and artificial concept that we use to separate an in-universe period of time and area of space where combat rules like initiative, positioning, and movement speed are important to keep track of. Unlike in some other editions, it doesn't really have much mechanical effect whether or not a character is in a battle or not. There are some rules for when a battle starts, because this is important for determining whether or not a surprise round occurs, whether targets are flat-footed, etc. But in general an encounter just kind of finishes when... well, when the GM decides there's not much point in keeping track of a strict turn order.
A good "rule of thumb" is that a character is involved in a battle if they're... well, participating in it. If the things that are happening in the battle could affect or be affected by the character. The specifics of this are not defined by hard-and-fast mechanics; you'll simply have to use your judgement.
As Adeptus's answer suggests, if there are two fights going on simultaneously in locations close enough to meaningfully affect one another, it's probably a good idea to model them as a single fight (or at least, to run them "in parallel", with a single initiative tracker), because it's entirely reasonable that someone could run from one to the other, or fire a crossbow, or whatever.
On the other hand, if Bob the Coward runs away in the middle of a battle and nobody on either side is at all inclined to chase him down, is it really worth anyone's time to sit there and keep saying "Bob's initiative. He runs another 120 feet further away"? He's ran away. He won't be affecting or affected by the battle in any immediate sense - he's just not participating anymore. If someone is chasing the fleeing character, or if they've only ran out to the edge of bowshot and are watching to see how the fight goes and might return at any time, then you probably want to keep them on the initiative tracker, because they can still effect the battle.
Overall, the point is that being in a battle or not being in a battle is chiefly a matter of whether or not you want to keep track of initiative, exact position, turn order, movement speed, etc. These mechanics are tools for resolving combats. If a combat is being resolved, these tools are useful ones - for most games, they are in fact vitally important.
If a character is not involved in a combat, these tools are probably not necessary. But you can still use them if you want.