What's the purpose of the trials of Job? What had Job done to deserve it? Was it necessary for God to destroy Job's life so utterly? What message does The Bible wants us to learn from Job's story.
I cannot agree that Job's religious observance was perfunctory as some answers above suggest. A simple reading of the book of Job indicates otherwise. In fact, God speaks highly of Job to Satan when he says
Hast thou considered my servant Job, that there is none like him in the earth, a perfect and an upright man, one that feareth God, and escheweth evil?
Interestingly, Job's friends who come to comfort him insist that he has done something wrong, or none of this would ever have happened. Job maintains his innocence, and at one point lashes out at them saying
Miserable comforters are you all.
In point of fact, God did NOT "punish" Job; rather he allowed bad things to happen to him to demonstrate to Satan Job's faith in God. The name "Satan" means "the accuser," and in the story, Satan suggests that Job only is faithful because of all his good fortune, but if he loses everything he would curse God. In fact, Job did not, in fact the book states
In all this Job sinned not, nor charged God foolishly
So it is wholly incorrect to say that God "punished Job--he did not. The story is to indicate that humans cannot always understand why things happen, but bad things do not mean a loss of God's love and care. An excellent commentary on Job may be found in Rabbi Rueben Kirshner's When Bad Things Happen to Good People. And speaking of reading, it would be a "good thing" if those who comment on the Book of Job read it first.
Job's trials were never intended as a punishment; in fact, he was a pious man and would have nothing to be punished for. Instead, the trials were a test of his faith. In the Book of Job, Satan challenges God for Job's faith even under extreme duress, saying that he is only pious because of his comfortable life. By removing the comfort, God tests Job's commitment and his real, objective belief in his religion. Although Job laments his misfortune, he never blames God, instead simply wondering why he was chosen.
You can also look at it this way: God was making an example out of Job. Sometimes we need a sacrificial lamb, someone who we can use to send a message to others not to behave in a certain way. It may seem cruel, but it usually works.
You can go around and around on this. One way to look at it is that Job did not really have a personal faith in God. He just did what he was supposed to do in term of religious observances and such. In this view, God's message is that religion should be about really caring about and having a relationship with God, not just checking off a list of things that you're supposed to do to be a good person.