In a lot of D&D-like systems, there's the concept of a 'teleport trap', which is almost exactly what you're asking for. The first example that comes to my mind is the teleport traps in Nethack, which will send you randomly to a different location on the same floor, or possibly to a different floor for specific types, when you step on a specific square.
As for whether or not such a device exists in D&D 5e, I'm not sure. I know they explicitly existed in 3.5e because I've run premade campaigns for 3.5e that had them, but I've never encountered them in 5e before.
Barring the possibility of an actual teleport trap in the official rules, you have two options:
1. If you're playing rules-as-written.
You can create a similar effect by using a Glyph of Warding with Teleport (or another spell that can produce the required teleportation effect) as the stored spell, and a trigger of a creature handling the warded object. This has a couple of specific limitations:
- For most teleport type spells, it's dependent on how the DM interprets 'willing'. Personally, I see three ways this could be interpreted in this circumstance:
- The creature handling the object makes it implicitly willing, independent of whether or not the know about the glyph or want it to go off. In essence, they don't care what happens as a result of them handling the item. If I were to rule like this, it would be with some obvious indication that the item was magical, so that they would at least have the knowledge that they probably should be careful with it, which would actually make it the next case.
- The creature handling the object is willing only if they know about the spell. In other words, they know something will happen if they handle the object, possibly even what, and their decision to handle it anyway is functionally an explicit expression of willingness.
- They are only willing if they know about the spell and want the specific effect to happen. This is likely how most AL DM's will rule, as it's the closest to the established RAI for the Teleport spell.
- Barring the above, you're going to have to use an AoE teleport effect like a Teleportation Circle, which will of course teleport anything within range when the trigger goes off.
- Independent of either of the first two limitations, this is probably going to be a one-shot effect. Glyph of Warding triggers, and then is of course gone because the spell completed. You would need an effect equivalent to the old spell Permanency to make it a repeatable effect.
2. If you're playing with the opportunity of homebrew rules.
If you're the DM, just do it, there's no reason (provided your players know to expect non RAW items and such) to not do so. Just be careful you don't make it feel like you're railroading (as both a DM and a player, I would consider this a borderline case).
If you're a player, talk with the DM and see if you can come up with something together to get the desired effect. Most DM's love creative players.
In either case, consider the possibility of a high DC Wisdom or Charisma save to resist the Teleport effect. This can help players feel like they have some chance of not getting caught by it, and can also lead to some really fun gameplay if you're using an AoE teleport.