From the Demonomicon:
When a particularly powerful demon perishes, its soul might persist for a time as a cacodemon.
Naturally only demons with souls can undergo this:
Obyriths and transformed primordials are among the few types of demons possessing souls, as are other creatures that metamorphose into demons through force of will or through exposure to the Abyss. Lesser demons form souls through experience, through servitude to demons with souls, or through consumption of soul larvae. Demons with souls can typically reason, connive, and plan more subtly than soulless demons.
So how can I figure out whether a demon might leave behind this soul-remnant? Does the 'powerful' stipulation refer to level, or their monster role? And would I just guess if they have a soul or not in the first place?