Cassette widths per Sheldon Brown:
Shimano 8 speed - 35.4mm
Shimano 9 speed - 36.5mm
Shimano 10 speed - 37.2 mm
Not the same, but kind of depends on the depth of threads on the locknut and how close the outer cog gets to your frame. May work some of the time, may not some of the time. The 10 speed outer cog will be 1.8mm closer to the frame than the 8 speed - that is a full 7-8-9 speed cog width.
Shimano 7, 8, 9, and 10 speeds all have different cog spacings - 5.0, 4.8, 4.34, and 3.95 respectively.
Remember that it is easier to put a narrow cassette on a wide free hub than the other way around.
On the Shimano 11 speed mountain (11-40, 11-42, 11-46), the outer six cogs are on two spiders, 3 per spider. The inner two cogs overhang the spokes. I have the 11-46 on a Phil wood 9 speed cassette hub on my Gus. It might not work on a freehub with a larger flange.
Laing