The 35-year-old, who skipped the entire clay-court season, has still only lost two matches this year en route to four titles, including the Australian Open in January.
Khachanov was leading 3-2 when Nishikori called it a day and will take on fellow young Russian Andrey Rublev in the quarter-finals.
Federer continued his career-long dominance over 134th-ranked Mayer, winning 17 of their 18 sets.
Federer showing his class, did not waste much time in clinching the second set and easily cruised to the winning mark, thrashing Zverev 6-3 in the second set.
However, he was defeated by Alexander Zverev in three sets in the semi-finals at Halle in 2016.More news: Outstanding Leaders in today's market: The Coca-Cola Company (NYSE:KO)
More news: GJM-police clash: IRB commandant seriously injured, says CM
More news: Justin Thomas shoots 63, trails Brian Harman by 1 at US Open
Rising star Zverev - who had also won three finals out of three in 2017 coming into this encounter - kept pace with his illustrious rival at the start of set two, raising hopes of an increasingly competitive contest.
Roger Federer reflected on a "difficult year" after beating Alexander Zverev to win a ninth Halle title as he provided the flawless platform to build upon for Wimbledon. While Zverev has improved by leaps and bounds, he still has the occasional drop in his game, and that's when veteran and elite players take advantage and find the opening to win the match.
Federer has reached his 11th final in Halle without dropping a single set.
Zverev has a very bright future in the game, and has a victory over Federer at this very venue. I'm very happy for him, how he's developed in the last years. "It will still be a very hard match".
Zverev managed to hold his serve at the third opportunity, but Federer broke again at 5-1 to claim the first set in just 22 minutes. I think going into Wimbledon he's going to be probably the favourite to win the whole thing.
Lopez, meanwhile, had to overcome a 45-minute delay during the second set, when he regained composure to see off Dimitrov, the player who had beaten him in the 2014 final at the west London venue.