I read the following article on Halacha and suicide
There is a Halacha is Mishneh Torah, Hilchot Sh’vuot, chapter 5, Halacha 17
If a person took an oath to harm himself, e.g., he took an oath to inflict injury upon himself, the oath takes effect even though he is not allowed to do so.44If he does not harm himself, he is liable for [not fulfilling] a sh’vuat bitui.
By that rational would an oath to commit suicide take effect?
I also don’t understand the Above Halacha, how can a shevua to cause bodily harm take effect when it is a sin?
How would such a shevua even be annulled?
It is my hope and wish that this question is merely theoretical in nature. Nevertheless, a person that does something so silly as to make such a oath is considered making an impossible oath, which is null and void. The reason is as the Radvaz on that Rambam explains, that we only say that an oath to violate an obligation is void, is if the oath violates a clear commandment, but not something that is only learnt from a drasha. We see that the torah (Bereishis 9-5) tells us specifically not to commit suicide in the words את דמכם לנפשותיכם אדרוש, I will avenge the life that you have taken from yourself. Therefore, such an oath will not be binding because we are already commanded not to do this.