Your criticism shows that you know a lot but there are two simple answers to your two valid questions. There was a time, when Mughals and Persians were political allies. Right after the defeat of Mr. Ibrahim Lodhi Sahab. So that makes Mughals & Pashtuns of Afghanistan stand on the rival ends. But Babar actually reached India passing through the Yousafzai territory. He was a commander of an army without a land to rule. Yousafzais actually helped him a lot. In Tuzk-e-Babari, he brilliantly described the Beer that Yousafzais made and how it helped him spend his winters :) Later on, everybody knows about the rivalry of Yousafzais and Mughals. And how Khattaks joined in against Yousafzais and then later on what happened to Khushal Khan. Political interests direct your relationship with other nations my friend.
As for Persians & Mughals being rivals, that happened too. Remember Nadir Shah who invaded India for looting and plundering in the disguise of a letter from Shah Waliullah. :) So yup, when the opportunity was there, opportunists were there too.
As for why Persians hated Afghans later on is because what I didn’t mention from that book was that it is believed that after Cyrus the great, another king (whose name I am forgetting right now as it’s all Cyrus, Darius, Darius II bla bla bla) who was loved by the Persians went to Afghanistan to fight different rebellions. There he was slaughtered by the Afghans. Afghans and Pashtuns have one problem even today. They pick a side in haste, then they become enemy with them, and then they fight back against them. Rebellion is in their blood because they cannot and will not be tamed. They can’t compromise.
So after Alexander took over, doesn’t matter what was the political status of Afghans in the Achaemenid Empire, they still had it coming by Alexander. Later on, Alexander did take a lot of revenge, but was weakened enough to explore beyond India and even to conquer India as a whole because of the constant on going war in Afghanistan that he thought he already won. You can’t move forward unless the states you control already are not a peace. 10 years and he paid the price of the revenge he took. Hope this answers your question.