Life insurance is basically a bet on how long a person will live, structured in a way to give a payout to a deceased person's survivors. Depending on how long the person lives, the payout may be larger or smaller than the total amount of payments the person has made to the insurer.
(If the payout is smaller than the total you paid in, your heirs would be better off if you'd stuck that money under your mattress, or in a savings account, or municipal bonds or something.)
Suppose you're the insurer. You are, in effect, a professional gambler. You are in the business of making bets and, in the long term, making money by making good bets.
If you're in the business of making bets, you don't make a bet with someone for whom it's not a bet but a sure thing. Professional gamblers don't play Find-the-Lady games.
In the case of life insurance, the insurer expects that the covered person intends to keep living. They may die soon due to an accident or unexpected sudden illness, but they themselves would prefer not to.
A person who already plans to commit suicide at the time they take out the life insurance policy, doesn't fit that profile. To them it's not a bet, it's a sure thing. There's no chance there. They may be doing it out of desperation ... but to the insurer's side of the deal, it's still a bad bet.
And since the insurer decides what policies they will write, they get to decide not to take that bet.