One gains mastery of the Elder Wand by besting the current master in a duel. This doesn't mean that one must kill the current master, but, given the bloody history of the wand, this is how most people have interpreted it.
Thus, when Draco disarmed Dumbledore shortly before Snape killed him, he gained mastery of the Elder Wand, although he didn't know it.
Voldemort didn't realize that disarming a person would have the same effect as killing them. He assumed that Snape, who had killed Dumbledore, had gained mastery of the wand. Thus, he murdered Snape in the hope of gaining mastery of the wand for himself.
Of course, Harry realized that Draco was the one who had really gained mastery of the wand, and so he went to Malfoy Manor and defeated Draco, thus gaining mastery of the wand for himself. Thus, when Voldemort attacked Harry with the Elder Wand during the Battle of Hogwarts, his spells didn't have a full effect or outright rebounded, because the Elder Wand wouldn't harm its current master.
Great until the last paragraph. Harry ws forcibly taken to Malfoy Manor and barely escaped thanks to Dobby. He disarmed Draco and took two wands, one Draco's of which Harry became the master. Only when Ollivander explained how it worked did Harry realize that he was Draco's wand's master and apparently later concluded that if the Elder Wand knew, he would be recognized as its master too because Draco had been the one to disarm Dumbledore. The other reason that Voldemort's spells were no longer binding was that Harry had meant to sacrifice himself for all of the people just as his mother had for him which lost even more of Voldemort's power whatever wand he might have used.