The target must be within 5' of YOU and visible
The distance between enemies has no bearing on this ability.
The 6th level Tipsy Sway feature of the Drunken Master states (emphasis mine):
When a creature misses you with a melee attack roll, you can spend 1 ki point as a reaction to cause that attack to hit one creature of your choice, other than the attacker, that you can see within 5 feet of you.
The distance of the first attack doesn't have a bearing on your ability. The only trigger required is that you are are missed by a melee attack. Once that trigger has been met, you simply have to meet the next requirement which is the target you use your reaction on for the Tipsy Sway reaction must be visible and within 5' of of yourself.
Suspension of disbelief
I totally get how this doesn't 'seem right.' It's difficult to come up with narrative explanations for a lot of the crazy stuff these characters can do. What we can choose to do is suspend our disbelief and have fun with whatever mental imagery we have in converting the mechanics into experience.
That mental imagery is going to be pretty personal. And honestly, the monk can be the most fun to do this with. I briefly played a goblin monk and the monk abilities are really kinda gonzo and I had a lot of fun coming up with narrative for what I was doing - especially things that really made little to no sense in terms of realism.
A personal narrative
As an example, maybe the original attacker comes in with their sword and misses. My tipsy monk sways around, slightly shifting the attacker closer while at the same time slightly moving the other enemy closer. The attack completes and everyone returns to their original positions before the next round begins.