Question: why dumbledore had to die?
Answer: Dumbledore died because that allowed the final showdown between Voldy and Harry to happen. Also also, he let Draco take out his wand, ensuring that Voldemort wouldn't become the master of the elder wand regardless.