The thing that relates them is D.
The meaning of D that they both have in their names is not yet known but it could be hypothesized that it could be a family or a village or a country in the void century.
They are both descendants of that family of D.
Following that line of thought it can be hypothesized that they have same ancestral origin and in the present time, they can be counted as very very distant relatives.
The family of D. has been divided into many branches over time but keeping in mind their similar antics, strong will and resemblance in their appearance it can be said that they belong to same branch and their ancestral trajectory didn’t wander much farther from each other.
They can both hear the voice of nature/things. It may be a characteristics of specific division of family of D or only pure blooded member of D. family. This merely strengthen the hypothesis that they are very closely related.
2-Other than that they are related by fate.
You might consider it too philosophical. But since in One Piece they often talk about fate, destiny, providence, history etc. It is also a plausible reason.
Maybe there are no coincidences in this world
It’s possible that everything happens for a reason
Fate works in the mysterious way
Whatever the case, Luffy has become a man worthy to wear that hat.
- Luffy wears the same straw hat that Roger used to wear.
- Luffy gets to see the view from the execution platform and almost experienced execution himself on the same platform and smiled at his execution just like Roger did many years ago. That was just like history repeating itself.
- Luffy went to Skypiea and in whale tree of Zou, most of the places that only Roger had visited before him.
So it is also a kind of relationship/link/connection they have.
In Manga/Anime, however, mostly people who have met both of them like Rayleigh and Shanks relate them on the basis of their crazy and fearless antics.. Smoker also immediately related them when he saw Luffy smiling at the execution platform.
*Theory by Aay Zee