An exemple will allow me to be better undestood :
There is two entites. Let's take Armor Stands. The player enters a command to make the nearest entity to him say "Hi".
At first, the command is executed sucessfully. But if the player moves to the second entity (who became the nearest to the player) and execute the command, the first Armor Stand will say Hi.
So the first entity keep being detected as the nearest one to the player, even if he is physically not.