It was a disgraceful dereliction of duty by the implementers of Aegis to recycle contact IDs so eagerly. With 4 digits it should have taken 10,000 subsequent contacts before that number came around again.
It was a lack of imagination. They didn't anticipate that case and probably just selected the contact IDs randomly. A bad RNG and an unlucky day is all it takes.
No amount of training is likely to completely remove human factors. It helps, sometimes a lot, but there's always going to be a bit of a difference thinking actual ordinance is currently headed directly at you.
We got _incredibly_ lucky. A Soviet submarine trying to get through the blockade believed that war had broken out and wanted to attack the US fleet with nuclear torpedoes [0]. Normally only two men aboard the sub had to approve the nuclear launch, and they both wanted to fire. This particular sub happened to have a third officer [1] on board who also needed to approve the launch, and he may have literally saved the world by disagreeing with the other two officers.
1. More time to think. An incoming F-14 is a minutes/seconds scenario; the Cuban crisis lasted 10 days.
2. "X did not happen" does not mean "Y was not a factor in X". The "about to get blown up" factor was part of the reason the Cuban missile crisis happened; it's also probably part of the resolution.