In an over the counter agreement between private parties, the lender is at risk.
For traditional shorting done on exchanges, the lending broker is at risk and is liable. Regulations exist to protect the parties involved but they are not infallible (margin requirements, etc.).
Shares in a cash account cannot be loaned out whereas shares in a margin account can be loaned out (the fine print) unless you sign a do not lend shares agreement. When you open a margin account, you sign a hypothecation agreement and sometimes a rehypothecation agreement where the broker can use your shares as collateral for his own loans and trading. Again, regulations exist to protect the parties involved but they are not infallible (for example, a limit of 140% on rehypothecation).
Share lenders (account holders) tend to have no clue that their shares are being loaned out unless their broker is sharing a portion of the borrow fee with them.
SIPC insurance covers the custodial function of a brokerage firm as well as as protection against unauthorized trading or account theft. It provides up to $500,000 in total coverage per customer for lost or missing assets of cash and/or securities. It covers up to $250k of cash. It does not protect one against loss of security value for their own bad decision making.