I’ve been using 50 and 51t cassettes with a medium cage 11sp SLX mech on my hardtail for a couple of years with no issues. Didn’t even need an extender thingy. Fitting the extender gives better chain wrap on the smallest cog but works fine without. There’s plenty of clearance with the b screw wound in.
My ebike came with 51t cassette and a medium cage SLX mech. No issues. Just swapped to a medium cage XT and again, no issues. This is 12sp though.
I reckon you’ll be fine although you might need a new chain as it might be too short.
But then a new cassette might need a new chain anyway.