Gittin (57b): It was taught: There was an incident in which 400 boys and girls were captured for prostitution. They realized what their captives wanted and they asked, “If we drown ourselves in the sea will we get the World to Come?” The most important of them interpreted Tehilim (68:23): The L‑rd said, I will bring again from Bashan, I will bring again from the depths of the sea.” This means that G‑d will bring again all those who drown in the sea. When the girls heard this they all jumped into the sea. The boys drew the follow conclusions from this. They reasoned that if the girls committed suicide to avoid being forced into a normal sexual intercourse then in the case of boys shouldn’t they commit suicide to avoid unnatural sexual intercourse? They then also jumped into the sea. Concerning them Tehilim (44:23) says: For Your sake we are killed all day long, we are considered as sheep being slaughter.
Tosfos(Gittin 57b): All of them committed suicide by jumping into the sea – In contrast it says in Avoda Zara (18a): ‘Let Him who gave me my soul take it away, but no one should injure oneself.’ [Thus one should not commit suicide even to avoid sexual abuse!] The answer is that in our case concerning the 400 children they were afraid that they were going to be tortured as it says in Kesubos (33b): If they had beaten Chananiya, Mishael and Azariah they would have worship the idol. Thus they would have tortured the children but not killed them.