Shakespeare didn't come up with this story all on his lonesome. (Don't call the plagiarism brigade just yet: most of Shakespeare's plots are borrowed, and people in the 16th century didn't think about "originality" in the same way we do.) The story of Hamlet dates back to at least the 9th century. It centers on "Amleth" (sound familiar?), a young man who fakes being crazy in order avenge his father's murder. Saxo the Grammarian included the tale in a 12th century text and later, François de Belleforest translated the story from Latin into French in Histoires Tragiques (1570), which is where Shakespeare may have found it.
Shakespeare's Hamlet is a play rife with moral dilemmas. Religious codes often clash with desires and instinctual feelings in the minds of the characters, calling into question which courses of action are truly the righteous paths. In Hamlet's case, such conundrums are debilitating and cause a frustrating, eventually fatal lack of action. Indeed, the absence of moral clarity in the play is arguably the root of most of the tragedy that is played out in the final scenes. Because of this, the issues in Hamlet provide an excellent basis from which to delve into an exploration of how religion motivates human actions. The characters' dilemmas concerning two great moral questions, suicide and murder, demonstrate the centrality of this motivation, both within the confines of the play and within the larger scope of human society.