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 filename, 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.