You can see what conditions TA will use the accounts primary name in this article:
The only known way for the Primary_Name_ID for an account to be set to a Name_ID not on the account is due to old bad data from conversion. It is not a widespread problem, so it should be fixed on a case by case basis.
The Primary_Name_ID for an account can be corrected by doing the following:
1. Go to the Names Entry screen and select whatever name should actually be the primary name for the account.
2. Click the check for "Primary Contact?" to make it preferred, then close Names Entry.
This will update the Preferred_Name_ID on the Named_ID 0 record to the Named_ID for that name. It will also set the Primary_Name_Flag to 'Y' on whatever name record you have checked it on. If you do not actually want that flag set for whatever reason you can then go and uncheck the "Primary Contact?" box, and that will set Primary_Name_Flag back to ‘N’ but leave the Preferred_Name_ID on Named_ID 0 as the name you would have checked.
If you want to correct the Named_ID on the transactions that use the bad one, you will have to adjust them and change which name the items are associated within the batch.