I had the same problem with an xt 10spd mech and a new sunrace 11-40 cassette, maybe the mech hangers are slightly different drop heights. I ended up getting one of those goatlink things for £20 which drops the mech down and back a bit more so clears the cassette now.
Just changed the cassette over from one bike to another. Both have the same model XT 10sp rear mech.
On the bike I was putting the 42 cassette on to, the mech arm (which has the cable clamp at the end) was scraping the 42t cog when I changed to a smaller cog. It didn’t have a problem with the original 36t cassette.
Very odd as the same 42t cassette with the same model XT mech on the other bike had good clearance? Both frames are non-boost.
The only difference I could see was that the mech hangers were different thickness, but being different (hardtail) frames I suppose there were plenty of other tolerences.
So I found a 1mm washer and stuck it between the mech and the hanger on the troublesome frame and it seemed to solve the problem by placing the mech further outboard. But it feels like a bit of a bodge! I covered everything in locktite blue just in case.
Looking at my other (3rd) bike with a SRAM rear mech, it doesn’t seem to have the cable clamp arm jutting out, so I wonder if this is just an issue with this type of xt.
Or perhaps I’m missing something blindingly obvious. Problem is I’ve got to ride 200km on it next weekend in darkest Wales I don’t want to die.