Is it bad to take out a life insurance policy right before you have a medical procedure?
Not if it's your own procedure.
If it is someone else's? Bad, because I'll just take a life insurance on them and then promise the doctor half of the proceeds if they ensure that the outcome of the procedure leads to an insurance payout.
If the only person who can get the money is you (or your partner or children or whatever), it’s fine as a form of compensation for potential damages.
If anyone, including your surgeon, can take that life insurance policy based on your life, things can go bad pretty quickly (hint: what happens if a profit-maximizing surgeon would earn a lot more money from your policy than from his regular job?).