is it legal
Technically speaking it should work assuming the editions are correct. Legal licensing questions should be directed to a trained microsoft licensing specialist or ask microsoft directly.
https://www.microsoft.com/en-us/licensing/existing-customer/activation-centers
--please don't forget to Accept as answer if the reply is helpful--