Spoiler Alert, click show to read: 
The wand was allowed to "kill" Harry the first time because Harry allowed it to happen (i.e. he didn't fight back) and because it knew Harry wouldn't die because he owned all three Hallows. The second time was when there was actual fighting involved, so that's when it betrayed Voldemort.