I think the major reason why he contemplates suicide is because he is constantly tortured by his fathers death. His father was murdered by Claudius and Hamlet wants to get revenge but cannot. He thinks about it but he doesn't do it because he knows that it is a sin in God's eyes.
Just an FYI, the first time we see Hamlet think about suicide is when Claudius requests Hamlet to stay in Denmark instead of going back to Germany (I think) to further his education.
Hopefully this helped and good luck.