Edit: I highly recommend reading u/NicLewisSLU as well, because he touches upon the origin of the word 'suicide', as well as how it was perceived in other periods than Classical Antiquity.
Yes, finally a question that I can (partially) answer! *insert my time has come meme here*
I can only answer this question regarding to Antiquity, since this is the subject I studied during college. This answer will also primarily be focused on the philosophical interpretation of suicide, not how the state or the common people interpreted suicide. It is especially difficult to know what the common people’s attitude towards suicide was, simply because there are barely any sources that tell us about that. I will start by explaining how suicide was seen by different philosophies, starting with Platonism and ending with Christianity. I will also shortly give some info on how suicide was seen in other genres than philosophical texts, before providing a conclusion that hopefully answers your question.
Suicide is something that is featured very commonly in ancient philosophy, from Platonism to Stoicism to Early Christianity. The most important question these philosophers asked themselves is, of course, ‘When is it allowed to take your own life?’. Here, we see that this question divide philosophies in two camps: those that think that suicide is almost always sinful, like the Pythagoreans, the Platonists and the Epicureans, and those that think that suicide can be committed under certain circumstances, which are mainly the Stoics. The Pythagoreans’ and Platonists’ reasoning that suicide is sinful, is mostly the same. They think that god gave our soul a body and committing suicide lets us escape this body god put us in. One can thus only die when god tells us it is time. Plato, however, gives us some exemptions for when suicide can be committed: when someone is morally corrupted, when the state tells you too, when someone has suffered so much shame it is impossible to still live decently and when someone is ashamed because he took part in morally unjust deeds. This are the only reasons when suicide is permitted; in all other cases, suicide is an act of cowardice to escape the hardships of life. This is supported by Plato’s idea that suicide is inherently disgraceful, while he also pleads that people that committed suicide should be buried in unmarked graves. Plato, but also Pythagoras, judges people that committed suicide very harshly. This mainly stems from the idea that the soul and the body are separate and that one can still have a good life as long as the soul is intact. That is why Plato permits suicide when someone who participated in unjust acts and not for physical hardships; in the first case, the soul is no longer intact, while in the second case, it is.
Epicureans, then, also had a somewhat negative view on suicide. There are very few sources on how they viewed suicide, but those that we have, tell us a lot. Central in Epicurean philosophy was being free from the fear of death. Epicurus believed that those that feared death, or organised their life to cope with this fear or committed suicide to be free from the hardships of life. Suicide is thus something negative; it is committed because one fears death. He also beliefs that somebody who finds multiple reasons to commit suicide, is narrow-minded. Epicurus however, just like Plato, permits suicide in some cases. Epicurism is focused on happiness and pleasure; illness, both physically and mentally, can compromise this. When somebody has a lasting illness that gets worse over time, Epicurus says that there are two possibilities: live with it and still try to find happiness, like Epicurus did, or end your life. Epicurus thus states that when it is impossible to reach happiness because of pain, you can commit suicide.
The Stoics, however, permitted suicide in more cases than the three previous philosophies. Zeno of Citium, the founder of the Stoic school, is said to have committed suicide. When he finished his lecture and walked outside, he stubbed his toe, cited the first line of the Niobe ’I come, I come, why dost thou call for me?’, held his breath and died. He saw stubbing his toe as a sign of god and believed that his time had come. Suicide was, however, not always permitted; they did have a set of rules. In the Stoicorum Veterum Fragmenta, these rules are stipulated. The first reason is suicide to save your country; the second because tyrants force us to do shameful things; the third is protracted disease preventing the soul from using its body; the fourth poverty and the fifth madness. However, another important aspect in Stoicism, just like in the other philosophies, is that god had to give you a sign to leave life. This, however, was more broadly interpreted than in other philosophies; Zeno’s story confirms that. In Stoic philosophy, ratio or logos can also been seen as a sign of God, since the Stoics believe that god is cosmos and logos. Humans possess logos, which means that if someone rationally decided to commit suicide, god gave a sign that it was permitted. This idea of rational suicide features frequently in the writings of Seneca, as well as Epictetus.
The final philosophy I want to talk about, is Christianity. When we think about suicide in Christianity, especially during the medieval and early modern age, it is clear that they did not allow it. It is evident that Christianity borrowed a lot of elements from Platonism and they also copied the idea that God gave us a body and we cannot leave it until he says so. However, the early Christians allowed suicide in some circumstances, especially if it was to achieve martyrdom. Some even believed that as a Christian, you should go to the authorities and proclaim that you are Christian so that you would be executed, but it would also make you a martyr. This approach was condemned by others, like Lactantius, but also by Augustine. Augustine was the most important philosopher in denouncing suicide because he was the first that used the Bible to vilify it. He simply said that the Bible did not allow you to kill someone, which is also applicable to yourself. He was not the first to criticise people that committed suicide, nor the last, but he was the most influential.
At last! My time of devilishly esoteric dissertation research is relevant on AskHistorians!
First I have to break up what we mean by "suicide." That term did not exist until the late-seventeenth or early-eighteenth century at the very earliest, and it is one of the first times that a term is used to describe the action of killing oneself in a morally neutral way. In Europe, the closest terminology in various languages (Latin, German, French and English) up to that point was some form of the phrase "self-murder." In the 1620s, John Dunne (of pastoral poetry fame) also coined the term "self-homicide" to refer to the act of killing oneself. The difference here may seem insignificant, but it is not -- homicide can be justified, murder cannot. The implications of these constructions tell us a bit about how suicide was seen in Europe and large parts of the Islamic world. That is, not only an act to be deplored as sinful or even diabolical (literally, caused by the devil), but also as a crime to be punished, largely by pauper burials as /u/call-me-ahab touched upon in their post. In Catholic canon law, these types of unmarked burials were referred to as 'ass-burials,' just to demonstrate the denigration that was put on the bodies of suicides.
That being said, suicide as the act of killing oneself is probably older than "civilizations" are. George Howe Colt in his book The Engima of Suicide describes how a number of primitive tribes, stretching from Egypt, to Cambodia, to North America, all have recorded reactions to people killing themselves. Generally the reactions were not pleasant; they were afraid of the idea of vengeful spirits or other ill-fortunes following the death of a suicide. Certain ancient civilizations, such as the classical Asian (Chinese, Japanese, Turkish) and Mediterranean empires (Romans, Greeks, et al) could find virtue in the act of killing oneself, so long as it was done in order to sustain one's honor, or at the very least to not avoid pain or punishment from losing a battle or committing a crime. Although the squeamishness many people feel towards suicide can be dated back to our most ancient forebears, the modern negative associations are generally attributed to Augustine and his unequivocal condemnation of suicide in Cities of God. In the western (Christian, Islam) worlds, then, the negativity of "self-murder" is a very ancient thing. Other forms of self-destructive behavior (for example, seeking martyrdom, going to fight a battle you know you cannot win) while seemingly similar from our point of view, were not considered the same by contemporaries until probably the Enlightenment. Anti-religious philosophes loved to challenge their clerical counterparts if Jesus had committed suicide by going to Jerusalem. The discourse surrounding topics like this moral problem, as well as issues like euthanasia, helped to form our value-neutral concept of "suicide." In that sense, "suicide" is a relatively recent phenomenon.
To answer your question more directly, chances are that people were killing themselves long before we even have records, due to reasons that generally go beyond the scope of what historians study (genetics, psychiatry, etc.). Human beings aren't the only animals that kill themselves - certain types of parasites demonstrate self-destructive behaviors - so the phenomenon of suicide, or something like it, likely goes back to the earliest stages of life on earth.
I'd be happy to do any follow-ups, but I'm currently still quarantined, so it might take me a while to respond.
Some suggested readings:
George Howe Colt, The Enigma of Suicide (New York: Summit Books, 1991).
Georges Minois, History of Suicide: Voluntary Death in Western Culture, Medicine & Culture (Baltimore: Johns Hopkins University Press, 1999).
Marzio Barbagli, Farewell to the World: A History of Suicide, Revised and updated English edition (Cambridge, UK ; Malden, MA: Polity, 2015).
Emile Durkheim's Suicide: A Study in Sociology tends to be the basis for most modern psychological/sociological studies of suicide. Even if his overarching claims are a bit outdated, it is definitely worth looking into if you're more social-scientifically inclined.