I am not familiar with these encoding stuff at all. I played a bit and found something interesting. The latex output when I open a listings inset with caption is different from when I insert a caption in lyx. The former has correct latex output.
I guess the problem is that the outer layout of this caption has language latex, so this caption inset has some 'initial language' latex, thus a change language is triggered. If we set runparams encoding of the caption paragraph to the encoding of the paragraph itself, the change of language can be avoided. Cheers, Bo