(I only have 10.04 here, hopefully this hasn't changed too much.)
Switching between layouts with ScrollLock indicating the layout is a supported configuration. It's set in System / Preferences / Keyboard / Layouts. You can set up multiple layouts and select a checkbox to use different layouts in different windows. In the Options child dialog, there is an option to “Use keyboard LED to show alternative layout”.
As to what is triggering a change, it could be when you change windows (if you have that option enabled), or it could be when you press a key (look under “Key(s) to change layout” in the Options dialog).
If it's neither of these and you do have per-window layout, there might be a window gaining focus and immediately losing it. When the problem occurs, try looking in the system monitor for active applications that might be doing this, or type
wmctrl -l in a command line and check if every line corresponds to something you expected (ask here if you have doubts as some window titles may not be self-explanatory).