While in the middle of an 800 km ride last week I noticed a repetative slight knocking coming from the rear cogs - specifically two of the mid-range gears which get quite a bit of use when I'm loaded up. Wouldn't go away and no visible evidence of anything wrong until I tried wiggling the cogs with my fingers while stationary and with the chain tensed. What I found was that with the chain in the lower gears - the smallest cogs - I could move the entire upper cassete back and forth by about 3 cms each way. If I put the chain up into the largest cogs I could do the same with the lower part of the cassette. Note: this only was possible with the part of the cassette without the chain holding the tension. When I returned from the trip - nothing bad happened except the continuing knocking - I compared with my mountain bike and I can't get that kind of movement on that cassette. So what's going on in there? I have no tools for dismantling the rear cassette and/or tightening it and wouldn't know how to go about it anyway. It looks serious and fortunately I wasn't all that far from home, but if I'd been in the middle of Tibet!!!! I can take it to my local bike mechanic but would like to hear what others might have to say. In all other respects it changes gear smoothly. It's Shimano Deora XT and only a year and a bit old so you'd think it wouldn't just fall apart.It sounds like the lock ring that holds the cluster on the freehub is loose to me.
The screw that holds the cluster together when you take it off usually does not attach the smallest two cogs, so it would make sense that they would move separately. So that screw is probably OK, but if it isn't sometimes it can protrude from the cassette and damage spokes.
If it was me, I'd take the cluster off be sure the screw that holds the cluster together is tight and reassemble and tighten the lock ring.
Another possibility is that the cluster was assembled without one of the spacers. If that were the case it would have been that way from the get go. I think that is unlikely as it would probably have never shifted right from the start.
Edit: I carry a Unior Cassette Cracker to remove or tighten the cassette on the road. I think it weighs less than an ounce and would allow fixing this pretty quickly.