Can you not select the LyX-Code directly, and inset->program listing? That would at least be clearer on the conceptual level, because you're going from verbatim to verbatim...
Actually, if I go from lyx-code to listings directly, this problem will not happen. I removed the lyx-code environment a bit too early. Anyway, it is better to crash lyx by a developer than by a user. Bo