To modify your legal name in your profile, you will need to ensure that your new legal name matches the name on the government-issued ID you'll present for identity verification. If you've already registered for an exam or service, changing your legal name may require Microsoft support approval. You can typically change your display name more easily, but for legal name changes, contacting support may be necessary if you encounter issues.
Make sure to follow the guidelines provided by Microsoft regarding name changes to ensure compliance with their policies.
References: