EDIT: This is what the wiki says on portals:
Portals do not permanently "remember" what portal they are linked to in the other world, but instead perform the following whenever a portal is used by a player:
First, if the portal block in which the player is standing has been used recently, then it will re-use the destination that was chosen the last time; in this sense, portals do "remember" their linked pairs, but only for about 60 seconds (1200 game world ticks, or 600 redstone ticks). One side effect of this behavior is that the cached destination is not validated before being re-used, so if a player travels through a portal and immediately deactivates it on the other side, other players can still follow them through for the next 60 seconds and appear at the same destination, even though there is no longer an active portal there. After 60 seconds have passed without anyone using the same origin portal, the cached destination will expire.
If the player's origin portal has not been used recently, then a new destination will be computed. First, the game converts the entry coordinates into destination coordinates as above: The entry X- and Z-coordinates are multiplied or divided by 8 (or 3) depending on direction of travel, while the Y-coordinate is not changed.
Starting at these destination coordinates, the game looks for the closest active portal. It searches a bounding area of 128 horizontal blocks from the player, and the full map height (128 for the Nether, 256 for the Overworld). This gives a search area of 257 blocks by 257 blocks, at the full height of the dimension being traveled to.
An active portal for this purpose is defined as a portal block which does not have another portal block below it, thus only the 2 lowest portal blocks in the obsidian frame are considered. A single portal block spawned in and placed using server commands would be a valid location.
If a candidate portal is found, then the portal will teleport the player to the closest one as determined by the distance in the new coordinate system (including the Y coordinate, which can cause seemingly more distant portals to be selected). Note that this is Euclidean distance, not taxicab distance. The distance computation between portals in range is a straight-line distance calculation, and the shortest path will be chosen, counting the Y difference.