Isolate wires soldered on PCB
Ideally, you should avoid finding yourself in this situation. Using appropriate connectors or atleast making sure you have enough room to comfortably attach the wires on the pads is a useful thing to do. You should certainly try to fix the problem more robustly if you want to produce or manufacture the thing.

For a one off thing, though, hot glue should work. There is a technique called potting, which using a different material, which does essentially what you imagine hot glue will do. Typically, potting is used to reduce stress at connector/solder joints and prevent cables from flapping around and so on. The potting material is better at doing this if the signals are especially sensitive in some way, since hot glue isn't a material explicitly chosen for it's insulating/dielectric properties. You should give it a go, though, for most applications it's probably insulating enough.