The short story is that Castiel was working with Metatron on a spell that supposedly would lock up all the 천사 in heaven, which Cas believed would give the 천사 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 천사 out of heaven. Which is what happened at the end of season 8.