The code cannot be used in a different country or region from the one it was generated for. Gift card and subscription codes are region-locked and the balance or entitlement cannot be converted to another currency or region, and changing the Microsoft account region will not fix compatibility issues.
The only practical option is to contact the retailer that sold the code and request a refund or an exchange for a code that matches the Microsoft account’s country/region. If the retailer cannot help, the code cannot be redeemed on an account in a different region.
References: