Why is this taught here?
Malbim: After telling how Shlomo succeeded as long as he went in Hashem's ways, it tells how at the end of his life he abandoned Hashem, and Hashem abandoned him.
Was he permitted to have all these women?
Radak: No. There were two Aveiros. (a) Even from Yisrael, he may not marry so many - "v'Lo Yarbeh Lo Nashim" (Devarim 17:17). (b) They were Nochriyos, who veered his heart to idolatry. He relied on his Chachmah, and said 'I will increase wives, and they will not veer my heart!' About this it says "a Chacham should not praise himself for his Chachmah" (Yirmeyah 9:22).
Malbim citing Mahari: There were three aspects of his Aveirah. (a) He loved Nochriyos - not like a man who marries a woman, rather, like a youth who desires, and his soul is tied to the one whom he desires - "Bahem Davak Shlomo Le'ahavah" (verse 2). (b) They were Nochriyos, with whom the Torah forbade to marry, even after conversion, i.e. from Egypt, Amon, Mo'av, Edom and Ches (one of the seven Kena'ani nations). (c) He married many. This is forbidden even if they are [Tzidkaniyos] like Avigayil.
Why did Shlomo marry Nochriyos?
R. Yosi (in Shir ha'Shirim Rabah 1:10): "Le'ahavah" - to make them love [Hashem], convert them and bring them under the wings of the Shechinah. Ohr ha'Tzafon (2, Pegi'ah Kalah
Is Bas Pharaoh not among the foreign women that he loved?
Rashi: She was dearer to him than all of them, therefore she is mentioned by herself. And similarly, "Tish'ah Asar Ish va'Asah'el" (Shmuel II, 2:30). 1
Rashi (Yehoshua 2:1, from Sifri): He endeared her as much as all of them, and she made him sin as much as all of them.
Radak: She was the beginning of his ruin, even though she did not veer his heart until he married many Nochriyos, and they veered his heart in his old age. He did not serve idolatry, but he let his wives serve idolatry, and he let them build, in Yerushalayim, Bamos to idolatry. Refer to 11:7:1:1,2.
Rashi (Shmuel II, 2:30): He was equal to all of the 19 others. Radak (ibid.) - he was more honored than the 19, so he is not included with them. Rashi (Yehoshua 2:1, from Sifri): He was as hard [to defeat] as all of them.