It isn't magic. Our consciousness exists because our brains can produce it, and our brains function because it's supplied by oxygen, nutrients and helped by other processes in our body. Why would our consciousness persist after brain death? That would break many physical laws.