Sovereign glue works underwater.
The glue takes 1 minute to set. Once it has done so, the bond it creates can be broken only by the application of universal solvent or oil of etherealness, or with a wish spell.
If water was considered a universal solvent, the description would very likely stop at water, and also not require a wish.
This trap would work as it is written.
Because it is a trap.
Trap Effects
The effects of traps can range from inconvenient to deadly, making use of elements such as arrows, spikes, blades, poison, toxic gas, blasts of fire, and deep pits. The deadliest traps combine multiple elements to kill, injure, contain, or drive off any creature unfortunate enough to trigger them. A trap’s description specifies what happens when it is triggered.
Things do what they say they do, and a trap that says works underwater, works underwater.
There are many examples of real-world adhesives that only work at particular heat, etc. So, of course, it's not a stretch that a Legendary, magical item could only work when there is interaction with it.
The trap does NOT take a minute to work.
This trap does not say it takes a minute, it says "If a character tries to grab the hilt of the sword [they are stuck and require a strength DC check]". Since the bond from sovereign glue is unbreakable after a minute, it makes sense that there is SOME bond before the minute is up and a strength DC could break that bond.