But the broker doesn't necessarily lend out the shares to his own clients. And even if he does, how does he get back the shares from the person who went long? The broker will have to buy other shares. But if the price of those shares is exploding, who is willing to sell them?
I'm not sure what you're asking. You only borrow shares if you're shorting. You just buy them if you want to go long.
The broker will handle finding shares to lend to you if you want to short. Liquidity is a separate problem, which is why you might have low spreads or not even be able to find shares to short in the first place. Your ability to short a stock is not guaranteed and up to the market conditions and broker risk. And like I described, if you borrow shares to short and the prices increases greatly, then the broker will margin call your account to buy them back forcefully.
I am not asking what happens if I short shares but if I lend to others my shares. If the broker cannot buy those shares back, I face the risk of losing them, don't I?
So I am wondering: does using those brokers come with the risk that I end up owning nothing if I pick a very successful stock?
The broker uses risk management, margin calls, market hedging, capital reserves and insurance coverage to ensure you always get your shares back. You're not really in any risk.
Capital markets are far bigger than you can imagine and unless you're holding millions of shares short (which is unlikely as a retail investor), it's not going to be an issue even with the most volatile penny stock.
In the miniscule chance that the shares are unable to be acquired for whatever reason, you would probably get reimbursed at the current market price, although I don't know the regulatory specifics around this and you should discuss the details with your specific broker.