Academic institutions didn't spring up out of charity but due to general idea of the rulers of the day that it will make their and their subjects lives better. This including both financial and non-financial gains, both affecting economy in general though not linked to it in detail.
This is why most big academic centers are government funded and not privately funded - and it's always a high risk game and few businesses like high risk. (Even startups, most go for low hanging fruit and quick returns. Academia in total is supposed to go for long game with high payout instead.)
Patents came out of the left field, to protect and enhance private research, provide more incentive to do so, cover the huge costs which few private companies could otherwise bear without exclusivity. (Because private company has to make profit while government funding does not necessarily directly because it has huge buffers of cash and social capital.)
Are you sure? Didn't the library of Alexandria invite academics and give them bed-and-board to stay and study? (It may have been one of the other early libraries??) With the aim to expand human knowledge. Yes wealth will always have a relationship with knowledge/wisdom but that doesn't mean supporting academia has to have other than altruistic basises.
Weren't a lot of early academic institutions monastic, seeing accrual of knowledge as a service to the world by leading to greater understanding of the creator? (Which you kinda intimate.) Isn't that "charity"?
Never mind that most of the biggest contributions to science had nothing to do with the market economy...