Those are intended to be friction-fit--the wavy tabs you see from the back grab the shower nipple. You might be able to remove the shower head, slide the trim plate off the nipple, flex the tabs a bit with a pliers, and reinstall.
However, a dab of clear silicone caulk could help keep it in place. Put the caulk far enough back on the nipple that it won't ooze out the front of the joint.
One other thought... if the trim rings move because there's a lot of movement in the shower head pipe (in the wall), that's a problem. It should've been secured near the nipple connection. If that's the case, some low-expansion spray foam would really help.