Shimano 12s cassettes are a new design--both in how they affix to the freehub body (Micro Spline only) and how they interface with each other / neighboring cog.
So the cogs from your 10s cassette will not pair with the 12s Shimano cassette as a proper system.