He had to die for several things to happen, including Maggie's character journey of leaving the group and the eventual conflict with Negan. Glenn also had to die to make Negan as dangerous as he became.