The Elder Wand's allegiance change from Draco to Harry is quite unique in the series, since it changed allegiance without having taken part in the conflict that caused its owner to be defeated (Draco at Malfoy Manor).
Since it wasn't present during the conflict, when did the Elder Wand realize its owner has been defeated?
- Immediately after Draco's other wand was taken from him by Harry (https://scifi.stackexchange.com/a/7250/20672 suggests this, but does not explain how or why)
- When the Elder Wand first came into the presence of the wand that used to be owned by its owner (in the Shrieking Shack), but now belonged to Harry
- During Harry and Voldemort's final battle, when the Elder Wand recognized it was dueling a wand that used to be owned by its owner, but now belonged to Harry
- ...something else?