If anyone was looking for the exact quote its from The Two Towers, Chapter 2 “The Riders of Rohan”.
“’Riders!’ cried Aragorn, springing to his feet. ‘Many riders on swift steeds are coming towards us!’
“’Yes,’ said Legolas, ‘there are one hundred and five. Yellow is their hair, and bright are their spears. Their leader is very tall.’
“Aragorn smiled. ‘Keen are the eyes of the Elves,’ he said.
“’Nay! The riders are little more than five leagues distant,’ said Legolas.
“’Five leagues or one,’ said Gimli; ‘we cannot escape them in this bare land. Shall we wait for them here or go on our way?’
If anyone was looking for the exact quote its from The Two Towers, Chapter 2 “The Riders of Rohan”.
So 5 leagues wasn’t even the limit for him, he could have discerned their hair color at an even greater distance.
I like the “lucky guess” theory. He’s bullshitting them.
His thought process was probably “we’re gonna run away anyways, I’m gonna tell these idiots I can see their hair color lol”