If there is a contradiction between something the Rambam wrote in the Mishneh Torah and his responsum letters, which is considered his final ruling? Is there a general rule or is it a case by case?
R. David Yosef in the introduction to the P'er Hador edition of Rambam's responsa quotes many who value the MT over the responsa, including Hida who writes in Birkei Yosef (OH 118:2) that it is obvious that the MT is to be followed over his responsa. In a similar vein, Maharit (HM: 7) writes that we generally follow books rather than responsa, since if the author intended to change his view he would have edited his book, and the responsum should therefore be assumed to be limited to that particular case. By this reasoning, if in the responsum Rambam indicated he erred, Maharit would agree that the responsum is followed.
R. Yosef also cites some who hold the opposite, such as the Radvaz (Divrei David 25, see also Shu"t 7:25). The Netsiv similarly writes (Meshiv Davar 1:24) that reponsa of all poskim trump their general halakhic compilations.
For further discussion, see Studies in Maimonides and His Interpreters (2008) by Marc Shapiro, pp. 70-76.
It's generally understood that the Mishna Torah was Rambam's last -- and therefore greatest -- work. We assume that he changed his mind over time from his responsa-writing period to when he wrote the Yad HaChazaka (i.e. Mishna Torah).
(Though much ink has been spilled about his responsum allowing conversion to Islam rather than death, vs. the Yad's prohibition.)