In order to answer this, let us first look at what Kant’s reasoning is for saying that suicide is immoral. Kant argues that suicide violates the categorical imperative in two ways. First, he says that there cannot possibly be a law of nature that says that people should kill themselves. Kant says that the maxim for a person who advocates suicide would be that self-love allows all people to commit suicide if their lives are going to bring more negative effects than positive effects. He then says
Now we see at once that a system of nature of which it should be a law to destroy life by means of the very feeling whose special nature it is to impel to the improvement of life would contradict itself and, therefore, could not exist as a system of nature; hence that maxim cannot possibly exist as a universal law of nature…
In other words, self-love is supposed to make us want to improve our lives. It cannot, therefore, make us want to end our lives. Therefore, this cannot be a universal law of nature.
Kant also says that suicide is immoral because it treats a person as a means and not as an end. One statement of the categorical imperative is that we must always act so as to treat humanity (and each human being) as an end in themselves, not as a means to an end. Kant says that if a man
…destroys himself in order to escape from painful circumstances, he uses a person merely as a mean to maintain a tolerable condition up to the end of life.
I do not think that I agree with Kant in either of these arguments. As to the first, I would argue that the maxim could be that everyone should commit suicide if their life is so bad that they cannot improve it. For example, if I am constantly racked with pain to the extent that I cannot concentrate on anything that will make me happy or allow me to grow as a person, I should be able to end my life. This is not contradictory because my life is no longer improvable.
As to the second argument, Kant seems to be saying that I should treat my body as an end. I do not agree. The end is my whole self. I want what is best for my body and soul. If my life on this earth is terribly agonizing, it may not be what is best for me. It may be best for me, as a whole person, to end this aspect of my existence.
For these reasons, I do not agree with Kant. I agree with his formulations of the categorical imperative in general, but I do not think they forbid suicide.