Apple - Primary display randomly changes
This worked for me, credit to this answer:
https://superuser.com/a/1220526/454133
Play around with moving the "top" bar between screens in the Arrangement window. Assign it to different screens and you will notice it will solve your issue once you find the "right" screen.
So, monkeying with the menu bar in the arrangement settings will reset your displays proper. I even got screenshots.
OSX has to guess which monitor is which, since the EDID info is the same for both (save the serial number, presumably, but OSX doesn't appear to pay attention to that). It usually tries to set things up to the previous setup by looking at how the devices are attached in the connection tree, however with Thunderbolt the connection tree isn't as simple as it was with displayport and USB.
You should be able resolve this by attaching one monitor at a time (ie, unplug the thunderbolt connection for the third monitor, attachthe second, then plug the third back in). However that's less than ideal, especially since all your apps will go back to the main monitor, rather than how you had them set up previously.
When Apple releases a refresh of the thunderbolt display, attaching one of the old ones and one of the new ones should also resolve the problem - they won't appear to be the "same" device, and so OSX will have an easier time keeping track of which is which.
Until that happens, another thing you can try is attaching the third one with a thunderbolt extension cable. It's an active device, and may alter the connection tree enough that OSX will have an easier time keeping track of it.
If that doesn't help, your best bet will be to wait until they refresh the thunderbolt display and upgrade only one of them when they do.
I suffer the same problem, each morning when I come to the office about 80% of the time my Mac wrongly selects the left most TB display as primary >:@
Getting tired of going to the settings display every time, I wrote a very simple console App to swap the screens for me: "ScreenPhant" (like elephants and memory; dig :-P)
It is really too simple, but I have no time now to make it any fancier (like staying resident and monitoring display changes automatically etc.). If you just start it, it will list the displays and serials. Pass the serial of the display you want as primary and it will set it. If you rename the App like "ScreenPhant_151d050f" it will use the _[serial] for the primary display so you don't need an extra script to launch it.
You can download here: http://www.dialxs.com/dev/ScreenPhant.gz Source is available here: http://www.dialxs.com/dev/main.c