Totalization Agreements are agreements that the United States has with a number of countries that exempt citizens of these countries from U.S. Social Security and Medicare taxes. These agreements prevent citizens of these countries from paying social security taxes in both their home country and the U.S. Since the U.S. has a Totalization Agreement with Canada, Canadian citizens on TN visas do not have to pay Social Security and Medicare taxes, but Mexican citizens are still liable for these taxes.
https://www.stilt.com/blog/2019/03/tn-visa-taxes/