Check out this previous post answered by /u/searocksandtrees.
https://www.reddit.com/r/AskHistorians/comments/2lqkyp/how_elaborate_were_booby_traps_in_ancient/
There is at least one historical structure, the tomb of Qin Shihuangdi, known to have included traps, although it has not yet been explored to determine their continued operation. This is not likely the origin of the trope, though. While exploration and excavation of old structures certainly has perils, the presence of intentionally-constructed sources of harm is entirely the result of misattribution by early archaeology and consciously non-factual reproduction of the idea by fiction writers.
Edit: Apparently this question has been answered (at least once) before, by u/kookingpot : https://www.reddit.com/r/AskHistorians/comments/2xibq8/ancient_ruins_with_booby_traps_in_them_is_that/