If I invested in a fund that's indexed to the S&P 500, and a company doesn't do well and drops out of the index, then the fund will sell that company and buy whatever replaces them.
Ideally, sure, the fund could have known ahead of time and sold before the company dropped out of the S&P 500, but that's trying to time the market, which generally doesn't go well over longer periods of time. It wants to capture gains in the aggregate over long periods of time, not maximize gains. The more individuals and firms try to maximize gains, the more likely they are to get bit over the long term.