That's basically what whole life insurance is, and it's a complete scam IMO because premiums are high (to allow for investment) and the investment is too conservative. You're much better off buying term life insurance and investing the difference.
You can partly do this DIY with self insurance. Basically, you put a certain amount of capital into a bank account or something and hand that over to the state treasurer in a trust, and it needs to be about $200-400k in my area (range is because the law isn't clear to me). If you can stand to part with that much, you probably prefer to have the insurance take that risk for you so you can retain control over that money and not worry about lawsuits.