New Hampshire was never a part of Massachusetts. I think you're confusing it with Maine, and that partition was approved by the Massachusetts legislature.
As for West Virginia, when Virginia joined the Confederacy they formed their own legislature loyal to the Union. That legislature was recognized by Congress, voted to partition, and Congress approved.
thank you to all who replied