As-Salamu `Alaykum Wa Rahmatullahi Wa Barakatuh akhi,
All thanks and praises are due to Allah, Lord of the Universe, and many prayers and much blessings be upon His Beloved Prophet and slave, Muhammad, and his family and friends altogether.
This happened shortly after Prophet Muhammad (may Almighty Allah bless him and grant him peace) revealed his revelation. Read this Hadith: A'isha, the wife of the Apostle of Allah (may peace be upon him), reported: "The first (form) with which was started the revelation to the Messenger of Allah was the true vision in sleep. And he did not see any vision but it came like the bright gleam of dawn. Thenceforth solitude became dear to him and he used to seclude himself in the cave of Hira', where he would engage in tahannuth (and that is a worship for a number of nights) before returning to his family and getting provisions again for this purpose. He would then return to Khadija and take provisions for a like period, till Truth came upon him while he was in the cave of Hira'. There came to him the angel and said: Recite, to which he replied: I am not lettered. He took hold of me [the Apostle said] and pressed me, till I was hard pressed; thereafter he let me off and said: Recite. I said: I am not lettered. He then again took hold of me and pressed me for the second time till I was hard pressed and then let me off and said: Recite, to which I replied: I am not lettered. He took hold of me and pressed me for the third time, till I was hard pressed and then let me go and said: Recite in the name of your Lord Who created, created man from a clot of blood. Recite. And your most bountiful Lord is He Who taught the use of pen, taught man what he knew not (al-Qur'an, xcvi. 1-4). Then the Prophet returned therewith, his heart was trembling, and he went to Khadija and said: Wrap me up, wrap me up! So they wrapped him till the fear had left him. He then said to Khadija: O Khadija! what has happened to me? and he informed her of the happening, saying: I fear for myself. She replied: It can't be. Be happy. I swear by Allah that He shall never humiliate you. By Allah, you join ties of relationship, you speak the truth, you bear people's burden, you help the destitute, you entertain guests, and you help against the vicissitudes which affect people. Khadija then took him to Waraqa b. Naufal b. Asad b. 'Abd al-'Uzza, and he was the son of Khadija's uncle, i.e., the brother of her father. And he was the man who had embraced Christianity in the Days of Ignorance (i. e. before Islam) and he used to write books in Arabic and, therefore, wrote Injil in Arabic as God willed that he should write. He was very old and had become blind Khadija said to him: O uncle! listen to the son of your brother. Waraqa b. Naufal said: O my nephew! what did you see? The Messenger of Allah (may peace be upon him), then, informed him what he had seen, and Waraqa said to him: It is namus that God sent down to Musa. Would that I were then (during your prophetic career) a young man. Would that I might be alive when your people would expel you! The Messenger of Allah (may peace be upon him) said: Will they drive me out? Waraqa said: Yes. Never came a man with a like of what you have brought but met hostilities. If I see your day I shall help you wholeheartedly."
He was scared and felt lonely in life and did not know what to do. Whenever he would attempt to kill himself, the Prophet of Allah (may Almighty Allah bless him and grant him peace) would see the Archangel Gabriel (peace and blessings be upon him) and change his mind. This was before the Prophet of Allah (may Almighty Allah bless him and grant him peace) even received Suratul-Fatiha if I am not mistaken, and way before suicide was made unlawful. He probably attempted to do it because it is part of human nature; when somebody feels terrified and insecure all the time he attempts to kill himself. It probably was not something big at that time as the people did not even have religion and did all sorts of sins openly.