TRAMP file names are somewhat different, obviously, to ordinary file
names. As such, the lisp functions
file-name-nondirectory are overridden within the TRAMP
Their replacements are reasonably simplistic in their approach. They dissect the file name, call the original handler on the localname and then rebuild the TRAMP file name with the result.
This allows the platform specific hacks in the original handlers to take effect while preserving the TRAMP file name information.