Stock markets are all about aggregating information about the state of the economy to discover its 'true' state at the current time. A trader makes money, on average, when they have knowledge that the market doesn't about a stock's valuation. By trading based on that information, they introduce it into the market, marginally changing the share price towards a value that incorporates their information.
When a trader's prediction is proven correct (assuming it is), they pocket an amount of money proportional to how incorrect the market was when they made their trade and how much of a risk they took (i.e, how much money they traded), thus being rewarded for the value of the new information.
Thus, the market is not efficient, but it asymptotically approaches perfect efficiency as the volume of trades increases. It's never 100% efficient but indexers assume it's close enough and that incentive of discovering the remaining inefficiencies is not worth the cost and risk. These days, that should be the case for most, if not all, individual traders.
If I understand things correctly, an index fund will end up reducing the efficiency of the market. But this is not necessarily a bad thing: it means that, as the portion of invested money that's in indexed funds increases, the value of new information that a non-index trader introduces to the market increases.
This creates a greater incentive for someone to discover and trade based on new information. The tension there will create an equilibrium point at some point below 100% indexed, meaning that the markets will never switch entirely to indexing.