Weighting by market cap ensures that larger companies (which naturally are a larger part of the economy) have higher representation, making the index more representative of the economy (or sector) that the index is tracking. It also keeps the weighing of each stock consistent even if the price changes, which has some mechanical advantages. As the price of a stock goes up/down, its weight remains constant. The biggest benefit is that index-tracking funds do not have to constantly adjust their holdings to match the weighting of the index. Cap-weighted funds are also not affected by stock splits, which have no real economic impact.
A counter-example is the Dow Industrial index, which is market-price weighted. Stocks with higher market prices make up a larger portion of the index, despite their overall size. It can mean that smaller, more risky companies can have greater influence on the index. Stocks can also split (or do reverse splits) to change their weighting in the index without changing anything fundamentally other than their per-unit price. It also means that market tracking funds must continually update their holdings to match the index (which is why you don't see many Dow-tracking funds).