The rear sprocket is typically held on by a retaining ring. It sound like this retaining ring has come out or is on it's way out. If that is correct. The best way to correct it would be to remove the wheel from the bike, Carefully remove the retaining ring by using a flat bladed screwdriver, remove the sprocket (it will come straight out) then clean out the grooves that the sprocket and the retaining ring go into. Then replace the sprocket, oh, remember which way the sprocket is dished, if it is not flat. And use a screw driver to get the retaining ring back on.
Let us know if that is the fix, or if something else is going on.