Is committing suicide legal?
In most countries, it isn't. It is against the law to take one's life, or the attempt to do so. So if you fail to commit suicide and get arrested, technically you could get prosecuted for attempting murder.
If you get arrested, don't worry about going to jail (at least, not in most civilized countries), because you will be declared insane, and therefor probably be sent to a mental institution.