There are many theories why dolphins and whales kill themselves on the beach.
But for my own theory and research, I say they killed themselves because dolphins and whales are very emotional creature. They are very emotional because they are very smart, intelligence and very loving creatures. So most likely they killed themselves because one of their member had died or sick, so this cause them to give up living and commit suicide.
We have seen some animals in the past where some animal become crazy and out of control after they loss their baby or their family member. Example we have many case of elephants become berserk and attacking a village after their baby died. And elephants also cry when their baby died, this proved this animal are very emotional animal too, and this also proved they are out of control when their family members died.
So for me, it is their “emotion” that the biggest cause why this creature kill themselves. Hope more research will be done in future to examine the emotion of this intelligent and this loving creatures.