(As someone who has never studied economics) The purpose of banks is to encourage the act of saving money. The problems you describe are with money itself; money, which is essentially a virtual representation of debt. I can highly recommend reading “Debt: The First 5,000 Years” by David Grabber.
In an ideal world, the purpose of banks is to take money from those who have it (at the moment), and lend it to those who need it (at the moment). In real life, most are basically organised criminals.
Thanks for the correction/elaboration! Yeah, banks most of the time seem to be a rather terrifying depiction of all the shitty parts of capitalism, though I still think the root of the problem lies with our imagining of currency.