Suicide is prohibited in the tractate of Smachot because it is considered one of the three major sins, murder. God gave life to man and therefore he has the right to take it away because God owns all. Committing suicide is the wrong reason to take a life and it's a disgrace to God. "God created man in his image" therefore, by committing suicide one shows disrespect towards God . .
The acceptability of suicide was based mainly on aggadic texts. This type of suicide often carried out in general manner in the Middle Ages as well as in earlier times, was honored as noble martyrdom. Therefore, it was clear that not all surrender of life could be considered liable by the law. At times it was even noble. However, the Talmud speaks in praise of the mass suicide by the drowning of young boys and girls being taken captive for a shameful life in Rome. The context of the passage indicates, however, that the children would be subject to sexual abuse (including homosexual activity). They debated whether they would go to heaven if they jump over board and drown themselves. They then remembered a verse they had learned: "The Lord said, I will bring back from Bashan, I will bring them back from the depths of the sea." On the basis of this verse, they decided they would go to heaven and therefore they all jumped into the sea. This is best known example as a source in Crusader times for how committing suicide was permitted. .
What about the story of the death of Rabbi Hannaniah Ben Teradion who was condemned to be wrapped in Torah scrolls and burn at the stake? Seeing this torment his students beg him to open his mouth and let the fire in so he will die faster and lessen his suffering but he objects . Why was this suicide and not a kiddush hashem? The Rabbeinu Tam answers this by contrasting this with the story mentioned above regarding the children who jumped into the sea. In the children's case they are allowed to commit suicide, but here Rav Hannaniah is not.