I have seen it mostly with firefox (don't remember with others) and any other type of window.
If it's Firefox windows and not terminal windows that switch workspaces on you, it is Firefox sending EWMH messages to steal focus, which can have the side effect of the window moving to the workspace that has the focus. Changing this requires disabling EwmhDesktops, or modifying it (there is no control for it, sadly) to disable the focus message — or inserting an earlier handleEventHook to detect and ignore the message without passing it on ("return (All False)"), which requires switching from the "ewmh" combinator to inlining it to your config, or writing a combinator of your own that you can stick in front of "ewmh" to override its handleEventHook.
--