Direct Gen 7 -> Gen 7 trades (Quick Link Trade, Link Trade, Wonder Trade and GTS) do not add memories or residence data.
Pokemon Bank does add some data though:
Gen 6 -> Bank -> Gen 7 = OT Memories retained; Residence history removed.
VC -> Bank -> Gen 7 = Residence updated (Latest added).
In both cases, notOT Memories = when it arrived via Link Trade at... somewhere. The Pokemon remembers {random feeling}.
Subsequent direct Gen7 -> Gen 7 trades will reset this to the default (seems to have a good memory, but it doesn't seem to be able to remember...).
Based on personal testing, I believe Gen 7 -> Bank -> Gen 7 will update notOT Memories and Residence only if the Latest (notOT) Handler is different to that of the receiving game. I tested the following using my copies of Y, Sun, Ultra Sun and Ultra Moon:
Sun (self-caught) -> Bank -> Ultra Sun = notOT Memories added; Residence updated (Latest added).
Ultra Sun (self-caught) -> Bank -> Sun = notOT Memories added; Residence updated (Latest added).
Ultra Sun (self-caught) -> Sun (via Quick Link Trade) -> Bank -> Ultra Sun (notOT Handler did not change) = no memories or residence data.
GTS (origin: Ultra Moon) -> Ultra Sun -> Bank -> Ultra Sun (notOT Handler did not change) = no memories or residence data.
VC Red -> Bank -> Ultra Sun = notOT Memories added; Residence updated (Latest added).
^ -> Bank -> Sun = notOT Memories updated (new notOT Handler); Residence updated (Latest updated and Past 1 added)
Y (heavily traded Xerneas with full Residence history) -> Bank -> Ultra Sun = OT Memories retained; notOT Memories added; Residence history removed.
^ -> Bank -> Sun = OT Memories retained; notOT Memories updated (new notOT Handler); Residence updated (Latest added).
As pk7 files do not contain the TID/SID of the Latest (notOT) Handler, I'm not sure if Pokemon Bank can detect whether the receiving handler is actually different if the trainer happens to have the same name as the current notOT Handler.