One problem with buying life insurance before you need it is that you need to make the term long enough to provide the coverage until the point you’re not likely to need it anymore.
This means that if you’re say 25, you want to get something like a 40 year level term coverage.
Insurance companies aren’t suckers. They know that the risk that you’ll die between age 25 and 65 is not negligible, and will price the policy much higher than a 10 or 20 year level term policy.
That’s why this makes sense, as you say, mostly if your family history includes early deaths. However, again, insurers aren’t suckers and they ask about that and price it in too.
In my opinion, the most reasonable is to only buy insurance when you need it. When you and your spouse buy a house, when you’re expecting a baby, etc. When this first happens, you’ll likely still be young enough and healthy enough to buy insurance at a reasonable cost.