First of all, Giles is a true historical figure, and Arthur Miller chose people who actually existed to be in his play, since it is based in history. Although he changed many of the details about the characters and added some situations to create dramatic tension, the characters themselves, in one form or another, actually existed. Corey is one of those. So that is one reason he was introduced into the play.
Another reason is that he is a rather unique case; he wasn't hanged like many others. Instead, he was pressed to death with rocks, for not giving the name of the man who said Putnam was "murdering his neighbors for land." In reality, he was pressed to death for not entering a plea of guilty or not guilty to the charge of witchcraft (not entering a plea kept him from being officially charged. If charged, the state took his lands away, and he wasn't going to give up his land, which would take it from his children.) Because he met such a unique fate, it is an interesting storyline to have in the play.
Lastly, Miller makes him sort of a comic hero. His wry sarcasm, bluntness, and lovable "grumpy old man" character brings comic relief to the play. This play is so heavy that a lightening of the mood here and there is greatly appreciated. And in the end, he ends up being a fearsome example of integrity, heroically dying to protect a man's life.
The Crucible is fiction; however, Miller's play is rooted very deeply in the history of the witch trials that occurred in Salem, Massachusetts, in seventeenth-century New England. Giles Corey is one of Miller's characters who is based on the historical Giles Corey who was a victim of the trials. Like the historical Giles Corey, Miller's character is one of the twenty innocent citizens who died during the hysteria in Salem. Also like his historical counterpart, Miller's Giles Corey is not hanged. He is "pressed to death" with heavy stones because he will not answer to the court. Miller introduces Giles Corey into his play because the "real" Giles Corey played a very memorable role in the actual witch trials.
Another reason is that Giles' character adds great drama and tragedy to the play. Giles is also a source of brief humor, allowing the audience some comic relief. Giles is a good man, John Proctor's friend. Like Proctor, he opposes the court in Salem and all the destruction it effects. Giles is a stubborn, cantankerous, sometimes foolish, and very moral man. When his innocent actions lead to his wife's being condemned, Giles suffers enormous guilt and tries desperately to save her. At his death, Giles proves to be a man of steely courage and principle. He chooses an agonizing death instead of cooperating. He defies the court and those in Salem who support it and saves his land for his sons, as well.