To merge an on-premises Active Directory UPN with a UPN created in the Microsoft 365 Identity Portal, you can use UPN matching. UPN matching is a process that uses the user principal name (UPN) to match the on-premises user account to a work or school account in Azure AD. To start the UPN matching process, you need to obtain the UPN from the user account in Azure AD, create a user account or update an existing user account in Active Directory Users and Computers with a user name/UPN that matches the target user account in Azure AD, and force directory synchronization.
However, it's important to note that UPN matching has technical limitations, such as only being able to run when SMTP matching fails and being able to use UPN matching only one time for user accounts that were originally authored by using Office 365 management tools. Additionally, the cloud user's UPN can't be updated during the UPN matching process, and UPNs are considered unique values, so you need to make sure that no two users have the same UPN.
If the UPN matching process doesn't work for your situation, you may need to contact Microsoft support for further assistance.
References: