Dumbledore had to die otherwise Harry Would not have been able to accomplish the task that he is destined for.
He would have always relied on Dumbledore to Find the Horcruxes and destroy them and the end Harry would have relied on Dumble dore to kill Voldemort as well.
So if Dumbledore hadn't died then HArry would never had been able to kill Voldemort