Seeing as to how the code works, now I see why the bug exists. It attempted to see if a ghost can be placed on the marked for deconstruction entity, and if so, considered that to be a valid place to move the entity to.
An idea, before moving the entity, is to look for entities marked for deconstruction in the new position. If any are found, place their respective ghosts exactly on top of the marked for deconstruction entities, prior to attempting to fit the ghost of the entity to be moved into its new position. If the moved entity ghost doesn't fit, after the deconstruction ghost replacements are placed, then the movement does not take place. Of course, all ghosts that were placed during this check are then removed.