How does the Put Back feature of the Trash work?
According to https://superuser.com/questions/59376/how-to-tell-where-an-item-in-the-trash-came-from, "I know the original locations are stored in ~/.Trash/.DS_Store". .DS_Store is the name of the file that stores various Finder-related information.

Following that question, there is also How do I check where the file in .Trash was removed from? and How to determine original location of file that is currently in the Trash?, which don't quite look like duplicates but talk about some of the details a bit more.