The short story is that Castiel was working with Metatron on a spell that supposedly would lock up all the angels in heaven, which Cas believed would give the angels time to sort out their issues. He succeeds in completely the spell, but Metatron reveals that all the ingredients he gathered was for a spell that would actually cast the angels out of heaven. Which is what happened at the end of season 8.
Because Medatron (How do you spell that name? :P ) had a plan to cast all angels down to earth and for that he needed Castiel's grace if I remember right