The Green Mile was really good movie, its been a while since i watched it but i liked it alot.
Uh, this might be a bit long so you might want to take it in small doses.
Anyways befor i explain what happens, there is no official reason given in the movie, or the book (yes its based of a book) for why john has such powers and abilites, there are just assumptions made as the characters imply or indirectly hint as to the answer. Anyway john=everyones fav inmate

, Tom Hanks=Paul Edgecomb, William=the evil inmate, percy=the stupid officer who sabotaged a elecricution, blah, blah.......
william is an evil crazy, who seems to be racist, at a point early in the movie william grabs john's arm, allowing john to sense william's evil actions, through this john finds out that william is the man responsible behind the rape and murder of two girls which john got the blame for (william killed some other people also, so he's on death row for that). John then responds by punishing williams by releasing the disease he exctracted from the terminaly ill wife of the warden and sending it to percy causing percy to turn his gun on williams and killing him befor percy fell into a perminant coma like state.
Now this confuses peter who asks john what has happened, john states he 'punished those men', takes peters hand and shows him the flashback whereby peter realises that williams was the killer of the two little girls which he discoverd from williams. Williams ends up dead and percy ends up in a asylum. unfortunatly for john, the courts think he is guilty of murder, and while perter and the rest of the officers offer to free him, he wishes to see things to the end and that there is no point in running (what with being a back man in 1935 and thus he is killed.
Now this is all quite confusing but this is where the implied parts of the story is explained. John has a few abilites, he is able to heal people and cause people to kill them selfs (my gusse is he can absorb the diseases of people and send transfer it to bad people in one way or another), he can also idenify if a person is good or bad and there past. throughout the movie he is considerd a miricale of the world, being a gental giant who dispite being persicuted still tries to help people. in fact it is considerd in the movie that he is a mirical of god. the officers suspect this (what with the miricales and all) and peter knows this, which is what prompts peter to transfer to a different facility after killing john.
Now peter didn't want to kill john and even offerd to help him escape, but john (for various reasons) knew it was worthless and so decided to face his fate. Peter felt it his duty to see john through and thus executed john in a manner of speeking. of course with john being the miricale he was and even healing peter, peter felt he had killed god's creature, his miricale. John then questions what he has done as he has effectively killed a innocent man who was in a sense, a healer.
Right towards the end an old john is seen explaining this to a friend of his whereby he states he rememers the events of 1935 because he is 108 years old. he feels that as john's execution took place a part of john's power jumped into peter, thus granting him a type of imortality as he is old enough to walk and talk and although he is elderly, dispite his appearence shows no sign of dying any time soon. It is implied that john was punished for the death of john, for not trying to save him, for not trying harder and as a result had to walk is own mile (the mile is a reffernce to death row inmates who take there last walk to the chair, effectively called the last mile, or in this case the green mile). He states that some green miles (namely his) is so long as he has witnessed the death of his kids (a parents nightmar apparently), grand kids, friends and so on, leaving him with nothing but to accept his punishment. Of coure he understands what he did was wrong and is left contemplating what he will say to god when his time comes and is asked why he "killed one of God's miricales".
Whew, that was long wasn't it, sorry about that, i wasnt sure what you were specifically asking so i tried to cover the entire ending. I hoped this helped and if you have anymore questions then just ask.