I see people here are saying keep the med school affiliation, which is what I’d likely do. That said, I can think of several instances in which physician authors reached out to me to change their affiliation on papers we worked on together because they had moved institutions before a paper was published (we even had proofs for one of the papers, so they were close to appearing in print and the work was clearly done while they were still at their precious institution). Only mentioning it to say I don’t think you’re doing anything particularly problematic if you do put the residency affiliation as it clearly happens.
That said, could always ask the senior author for advice on this if it is eating at you. I could only see it mattering if you’re publishing some big NEJM paper as a first author and your institution wanted to use it for media as “a paper out of x published in NEJM showed...” - then maybe think more carefully!