Normally, there is a small tab on the switch housing that goes into a small hole in the handle bars to keep it from moving.
If that tab is gone, like you are experiencing, the housing will rotate.
One thing you could try is to get a thin strip of rubber to go between the housing and the bars.
A strip of sandpaper (cloth backed would be best) could probably also work well.
AKA: Tim & 'The Adventure Cycle' VROC #24567, NEVROC, SteelCity VROC
"When life throws you curves,
Aim for the apex."