Well the T3SS system component of the flagellum can function as a protein translocase in the flagellum. In the flagellum it exports the rod, hook, cap, and filament proteins, so it is still able to perform the function of the homologous structure despite their sequence divergence. That could easily have been the ancestral function of that part of the system.
All of this is discussed at length in Nick Matzke’s 2003 article on the flagellum, including your questions about the filament proteins, which are homologous to adhesins, known to be secreted by pili-bearing bacteria, pili which are exported by their t3ss homologues. Bacteria bearing pili secreting adhesins use them when they float around to secure themselves to surfaces. It all fits together.
Flagella even today can still function as adhesins, despite their sequence divergence from adhesins. They don’t just give motility to bacteria, see
Moens S, Vanderleyden J. Functions of bacterial flagella. Crit Rev Microbiol.
1996;22(2):67-100. Review. PubMed PMID: 8817078.
Hilariously, there are flagella that have enzymatically active filaments. Literally the flagellin proteins are active enzymes catalyzing the chemical degradation of extracellular proteins. See
Eckhard U, Bandukwala H, Mansfield MJ, Marino G, Cheng J, Wallace I, Holyoak
T, Charles TC, Austin J, Overall CM, Doxey AC. Discovery of a proteolytic
flagellin family in diverse bacterial phyla that assembles enzymatically active
flagella. Nat Commun. 2017 Sep 12;8(1):521. doi: 10.1038/s41467-017-00599-0