That's an interesting issue. When you select text, a new element is added at the end of your selection to help position the "quote this" popup. That element is normally completely invisible. However, when you click the spoiler toggle, the contents of any elements within a part of the header are replaced with the new spoiler text, so if the new element is there it will also get updated. You have to get the selection exactly right though - any tighter and it will get lost when the header is updated; any wider and it is no longer within the necessary part of the header.
I will report this to IPS because there are other subtle things that I don't really like about this implementation, but it may well not be fixed soon because it is just a hard-to-hit cosmetic issue.