Firstly, pension funds hold some share of stocks, but far from all. Second, pension funds hold a share of a pie that's not all that came out of the bakery. The bakery made a lot more dough, but much pie was spent (horribly mixing metaphors) to buy assets like property and private investments. So in reality pension funds hold a fraction of a fraction. Third, pension funds invested in equity is a replacement for the old pension systems of yore where companies were forced to set aside money and invest smartly to fund guaranteed income pension plans. They don't have to do that anymore. Instead they contribute to a 401(K) or similar in other countries, which lowered their costs and reduced company risk. For listed companies, those savings went to the shareholders, of which pension funds were just a fraction of a fraction.
I hope this illustrates that we, the salaried workers, see only a small fraction of the value created by increased productivity.