What am I doing wrong?
42t 10-speed sunrace cassette on a SRAM 745 (?) hub with a Shimano 10 speed XT rear mech (M786).
The lever arm bit where the cable attaches ends up rubbing on the 42t sprocket in the higher (few sprockets) gears.
If I remove the spacer behind the cassette it's then fine (but the cassette is unusably wobbly).
Do I need a longer B-screw? Or is this combination just not going to work?

B screw isn't going to help this, B screw is to make sure the right amount of chain is between the top jockey and the cassette. ย (1.5 links is usual). ย This is simply a derailleur that's the wrong shape for anything this large in cassette terms.
Someone else posted about this recently. ย Seems the SLX GS has a different shape and doesn't do this.
OK, that makes sense.
11 speed SLX is probably going to solve this then (same cable pull) ?
Or maybe a goatlink?
From my thread about the sunrace 12-50 I can confirm this issue is reduced/gone when using a gs cage slx mech.
Admittedly on an 11 speed system but your problem is very similar to the one I had.
Any pics of the mech from side on?
My money is on the mech hanger being in the wrong position for it to work.
There was a long thread on here about it back when expander cogs on the rear were new.
The hanger on some frames is rotated backwards(clockwise) to far and it causes this problem.
I stopped this from happening on Mrsstus Nimble9 by grinding down the tag on the mech that sits on the stop of the mech hanger. That let the mech rotate round (anti clockwise) a bit more and it all worked fine.
Goatlink, RADR etc are designed to tackle the issue of the jockeys being in the wrong place even after you've made them clear the cassette with a longer B screw or winding the screw all the way - different problem. ย The Goatlink *might* accidentally solve the problem by moving the whole mech, but it's not what it's designed for and I'm not sure if it would actually work.
Looking through the current stuff on Shimano, if you want to stay 10 speed, this is pretty much your only officially supported option - anything else is trial and error...
It's on an On-One Codeine; I don't think there's anything wrong with the hanger (unlike the PP problem SStu is referring to).
I'm pretty sure that I could just put an 11-speed rear mech in and solve the problem, but it's kind of a waste throwing away a perfectly good 10 speed mech. I could leave the shifter, cassette and chain as they are.
Here's a side-on view (with the rear mech removed).
https://flic.kr/p/FczSan ]2018-03-03_09-18-33[/url] by [url= https://www.flickr.com/photos/36306029@N0 5" alt="" width="480" height="359" />
There's nothing "wrong" with the hanger.
It's just not designed to work with a 42T.
If you want to use the mech you have just grind/file down the stop on the B knuckle.
A pic with the bike the right way up and the mech attached will show the problem up better.
https://flic.kr/p/24MWiAY ]2018-03-03_09-50-24[/url] by [url= https://www.flickr.com/photos/36306029@N05 /" alt="" width="500" height="374" />
I have the same setup with a similar mech (xt M781) with no issues, so it will be a peculiarity of your particular frame/hanger setup.
The more modern mechs (m7000/8000) are designed for larger sprockets, and will work with 10spd shifters OK, I believe.
I'm using that exact cassette and mech on my solaris but with a radr cage. No fouling issues here.
The mech does look like it's rotated clockwise a little.
As I said grind the stop on the B knuckle to allow it to rotate anti clockwise a bit and it'll clear.
Ideally you want the bottom bolt on the B knuckle to sit a bit lower than the top bolt.
If you look at your pic they're almost in line with each other.
You might want to put a longer cable on there too. Looks like thats also stopping the mech from rotating.
I ran an 10 speed 11/42 with an XT long cage and goat link on my last bike with the Sunrace. In fact it's now on my son's bike. The ghost link was not really necessary but improved shift a little.
I use Shimano Deore M6000 - I think in the so called "GS" version, made for 42t.
2x10 set up
Front 24 + 34
Rear 11-42
Price for the Deore M6000 rear mech is around 50 bucks. Works without issues - simply fantastic! Bit of a "mountain goat" set up.
As far as I remember there are two or three versions of the M6000 rear mech. Only one is made for the 42t setup.
Replaced an old Deore XT 3x10 setup with above. No issues.
I tried filing things down, but got bored pretty quickly. Goat link arrived today, works great, problem solved!