The souls/spirits which go to barzakh are the ones who as humans have done zikr of Allah so much that they have made their souls powerful in their lifetime and had control over their nafs.
when a human dies, a powerful soul is strong enough to fly towards barzakh. a weak soul remains in grave until someone like children offers koran, nafal for them, or some sadqa e jariah helps the soul becomes strong over some amount of time and then it makes to barzakh.
the weak souls in grave or the souls wandering about are also captured by BM's and used like jinns for BM.
the souls which get different type of tasks are strong souls which are near and dear to God. They maybe given duties in human world, or in barzakh or skies or any of the 18000 dimensions. such duties keep on changing over the course of time.