Some types of brokerage accounts allow the stock broker to lend my shares to short sellers (probably without needing to notify me). Do I incur any risks when I sign up for such accounts? Is there any risk that I can lose my shares? If there are risks, how am I compensated for the risk (e.g. higher interest rates on idle cash, a small share of the commissions from the short seller, etc.)?
Jurisdiction matters so my answer is applicable to the USA.
SIPC insurance guarantees the custodial function of brokers so if the borrowing broker defaults, you won't 'lose' your shares. I would surmise that this is not your problem because you own the stock in book entry form at your solvent broker and therefore you have the right to sell them at any time. Therefore, default is an issue when it's your broker that goes under.
Some brokers share a portion of the borrow fee with the lender of the shares (you).
When a dividend is paid, the buyer of the borrowed shares receives the dividend. The share lender (you) receives payment-in lieu (PIL) from the trader who shorted the shares. The downside of PIL is that it does not qualify for favorable tax rates on qualified dividends and they are taxed at ordinary income rates.
Shares in a cash account cannot be loaned out. When you open a margin account, there is a customer loan consent form. You do not have to sign it but if you don't, the broker can refuse to open margin the account.