I think there is a need to put the Battle of Shanghai in its proper historical context. At that time, KMT was lobbying hard for western (US in particular) support against the Japanese in the Sino-Japanese War. However, the western perception was that China is unable to defend itself against any foreign aggressors (as demonstrated in the many decades prior to Sino-Japanese War, such as the Opium Wars). Hence, KMT needed to demonstrate that Nationalist China is different and that they are able to put up a good defence of their own country.
Thus, KMT threw in their best divisions in the Battle of Shanghai to prove this point. At the same time, Chiang Kai-Shek's wife, Soong Mei-Ling (宋美齡) was in US lobbying for US' support against the Japanese. This was a famous historical event in the US as she was the 1st Chinese national to address both Houses of US Congress. While this lobbying is going on, the KMT divisions was putting up a good fight against the Japanese. Much better than any western countries thought possible by Nationalist China.
At that time, there was also increasing concerns about Japanese atrocities in China by western countries. However, whilst western countries wanted Japan to stop carrying out these atrocities, they didn't do anything to stop Japan (i.e., no embargoes or sanctions). As a result of the Nanjing Massacre, which was well documented by foreigners in Nanjing, the western world came to condemn Japan for it. The pressure was so great that the Anglo-Japanese alliance dating from before WWI was broken off. This set the stage for the isolation and embargo of Japan by the various western countries that ultimately led to the outbreak of the Pacific War and the defeat of Japan by the Allies.
Yes, the Nanjing Massacre was unforseen. However, the loss of Shanghai was expected by KMT despite their best troops being committed. KMT wanted to slow the Japanese and show the world that Nationalist China is not the same push-over as Qing Dynasty China.
If KMT reserved their best troops and just allowed token resistance at Shanghai and their capital Nanjing, this would be the equivalent of the foreigner militaries marching to Beijing during the Qing Dynasty. And it would be the end of Nationalist (KMT) China. The KMT leadership is aware of this since they grew up / took part in the Xinhai revolution, which is why they committed their best troops.
Also, your point about not committing a country's best troops to defend the country and its capital is rather strange to say the least. If that is not the time to commit the best troops, when should the best troops be committed?