It’s impossible to go into an animal’s head and determine if it is intentionally killing itself. We also don’t really know whether or not other animals’ brains even have the capability to consciously take their own lives.
But from some experience I’ve seen some animal behavior that resembles suicide. My mother had a lot of fish tanks, and sometimes fish would jump out of their tanks and die, even if they were alone in the tank. I forget what kind of fish it was, though.
Whales are also known to beach themselves when they’re still alive and unharmed. It’s unknown why exactly they do that, but there may be a number of factors. This Scientific American article mentions red tide, pneumonia and injury as cause for self-beaching. Some also believe that the amount of noise pollution caused by ships causes whales to get disoriented and beach themselves. I would definitely believe in that possibility; ships create an intense amount of noise above all the pre-existing natural noise, and whales have much more sensitive hearing than humans.
Still, I don’t know if I would call this deliberate suicide. In the case of injury or illness, I can imagine that a whale might sense its time is at an end, like I’ve experienced with dogs and cats. But it seems like dying by being crushed by your own weight seems pretty painful…