One of the ideas that Hume sets out to attack is the preconceived notion of cause and effect. He makes a distinction between things that are truly connected and things that aren't necessarily connected, be are perceived as such because of prior knowledge and experience. We think that it was A that caused B, because in prior events A has always been followed by B. Hume applies this idea to the field of science, but he also applies it to his ethical theory.
Hume argues that just in science, in morality there are assertions of what is good or not. Those assertions are based in the experiences and emotions, feelings of approval or disproval that result from previous external events. According to Hume, we are inclined to make an moral association between an event and the emotions it caused. This is how the individual comes to a conclusion on whether or not something is good or bad. This logic basically implies that there is no subjective good or bad, only our interpretations which are founded on emotions. After having examined reason and sentiment, Hume arrived at the conclusion that our ethics are based on sentiment. So then why is it that we all have the same basic sense of good and bad? Well, Hume attributes this to the fact that we are all of a similar psychological construct. And when we do disagree, it is because we are not in agreement over the circumstances or the consequences.
Hume notes a coincidence between the things that we generally disapprove of as a society, and the things that benefit our society. Based on this he argues that our ethics are based on the interests of our society. He cites "public utility" as the basis for all of our moral assumptions. Hume asks what would become of justice in a hypothetical situation where we could have everything we needed and wanted, and then in another situation where we had barely enough to sustain ourselves. He feels that in the former there would be no need for justice, and that in the latter there would be no regard for justice. Thus, justice is born out of the needs of a society.