We know that Blackbeard’s Yami Yami no Mi can pull things inward making parallels to gravity and the way black holes work.
Blackbeard studied the lore extensively of Devil Fruits, so it is not far off to say that his ability is able to nullify devil fruit powers because the dark evil nature of the fruits powers at their core is able to be pulled by his darkness. The darkness of the fruit-eaters ability which gives them the described ‘demonic’ powers is within their body, unless awakened, which is why he must be touching them to drag the power inside and hold it hostage.
Ever since Blackbeard murdered Thatch and took the ability for himself and learned about how it worked and researched it, we can assume while digging deep into its capabilities and the lore he reads on the fruits he had an epiphany about where the fruits demonic essence gets transferred to once its living vessel is no longer living. Which is where he began to formulate his idea and would go on later to attempt it at Marineford.
But what is the basis for this ‘magic trick’ one might wonder? Well my theory is very simple on it:
Similar to when he nullifies a vessel-bound devil fruit ability of an active user, as a user dies and becomes a vacant vessel, the spirit energy or demonic presence of the ability heads off to possess a similar fruit to go back into circulation, this is already established in the One Piece world.
So what he does is he uses the ability of the Yami Yami no Mi to pull the power which lacks a vessel into another vessel. Whether that is another person under the black sheet with him, himself as a one-time thing, or a similar fruit to the fruits description in the Devil Fruit book, does not matter.
This is why when Absalom is killed, it is assumed he used the power of the Yami Yami no Mi to capture and transfer its demonic essence into a new vessel of his choice.
*Theory by YuliaVeil