I was trying to make a teleportation machine for my realms when I found this bug. at first I was trying to have three command blocks run the /tp command at the same time. I also powered it from the same side and it teleported other players too. the commands were, (/tp @p 1000 4 ~) (/tp @p ~ 4 1000) (/tp @p ~ 4 ~100). The numbers change cause the 3 commands get randomly picked so it'll be a new location every time. After that I tried it with only one command block (/tp @p 1000 4 ~) and it still teleported more than one player. I don't know if it's a problem with realms or the /tp command of the @p variable.
When command 1 teleports player a, then player a may no longer be the closest for command b. This is what causes your issue, you might want to tag the player (using scoreboard) to get around this behaviour.