Mastery in a dominant foreign language (especially English obviously but even French or Portuguese) comes with a lot of advantages socially and professionally. It sets you apart from those who speak “only” local languages, is useful for international trade (even with neighbouring countries, not only the former colonial power) and service opportunities (process outsourcing).
That pressure keeps language use alive in spite of a deliberate push to establish a “national” language, e.g. in primary education. In Algeria, paradoxically, distinction through mastery of French became even more powerful as the government was trying to promote Arabic and teaching French became deemphasized in public primary education. Only an elite had access to French schools (and therefore an advantage in higher education at home and abroad). It's also not the case that all tertiary education is in French but that creates other hierarchies.
It's also important not to underestimate the fact that none of these countries are fully homogeneous culturally, there are (hundreds of) millions of people who do not speak Arabic or Hindi/Urdu or only speak it as a second language they do not identify with. In Algeria and Morocco, there is also a gap between the variants of the Arabic language used in teaching and the vernacular (darija).
Finally, beyond the various factors that have an influence on language use, one basic fact is that governments cannot engineer a switch from one language to another, root out foreign influence, or prop up a local language at will. Linguistic policy is often very contentious but ultimately a lot less powerful than often assumed. Another area where that's evident is minority/local languages in Europe.