HDI is not the only source.
Still, it's oftentimes a useful indicator.
Iran has oil and a very small population compared to India.
Other than that Iran is most heavily sanctioned, as opposed to India. And most of Iran's governmental budget is not sourced from oil revenues anymore.
Tell me why are Sunnis in Iran treated like 2nd class citizen?
Not true, Sunni Muslims are treated with respect and dignity. In Iran there are more Sunni-led mosques per capita than Shia-led ones. The country is home to several Sunni Islamic theological centers of learning, as for example in Bandar Abbas or in Golestan province, which even attract foreign students from places as diverse as Iraq, China or Africa.
Sunni Muslim citizens have their own representatives in the Iranian parliament, a Sunni Muslim commander is heading the Iranian Navy.
Moreover any and all forms of sectarianism are clamped down on. Iran's Supreme Leader issued a fatwa banning slander against historic figures revered by Sunnis, while the token Shia currents which engage in anti-Sunni sectarianism (like the Shirazi clan or Hojjatieh) are outlawed, many of their members jailed, their media banned.
How about minority groups like Kurds, Balochis, Armenians etc... If you are not Persian/Azeri and Shia muslim. You are treated like garbage. This is why Iran is backwards.
That too is far from being factual. The secretary general of Iran's Supreme National Security Council, Ali Shamkhani, is an Arab Iranian from southwestern Khuzestan province. Former head of the national police force, current speaker of Majles (parliament) and a leading politician in the principlist ("conservative") camp, Baqer Qalibaf, is a Kurdish Iranian. Members of all linguistic groups are present across state institutions and have free access to all sorts of professions.
There's no ethno-linguistic based discrimination in Iran, neither on the state- nor on the societal level. In fact, Iranians hardly care about nor ask people what their ethno-linguistic backgrounds are. And more importantly, the majority of Iranians are of mixed linguistic descent anyway, so most of them cannot be categorized into one distinct "ethnic" group to start with.
If we were to compare, communal strife involving religious and ethnic minorities happens to be more intense and widespread in India. And that's while unlike Iran, India doesn't have the world's hegemonic superpower, the influential zionist entity and their full array of client states lined up against it trying to destabilize it by any and all means including through support for sectarianists and separatists.