I assume the episode takes place in the middle of Empire of Death, and once that airs it will be clear how and why the Doctor and Ruby wound up in a memory TARDIS. Given how clearly (IMO) this thing's set in media res, I'm surprised more people aren't automatically reaching that conclusion.