@Shekhar, Sumeet (Cognizant), Thanks for posting in Q&A.
From your description, I know that you encountered an issue that Intune Autopilot Device Name template settings does not work as excepted.
Based on my research, there could be some reasons for the issue.
1.This happens if you enroll the device before the Autopilot profile has been assigned to the device.
2.To apply device name template, it requires Windows 10, version 1809 or later, and Azure AD join type. Also, names must be 15 characters or less, and can have letters, numbers, and hyphens. Names can't be all numbers. Use the %SERIAL% macro to add a hardware-specific serial number. Or use the %RAND:x% macro to add a random string of numbers, where x equals the number of digits to add.
3.This typically happens when Autopilot enrollment is run on a Wi-Fi network or using an external USB ethernet dongle. So, in general it is caused by network latency that results in the client not downloading the correct policies from Intune before enrollment continues.
As for fix it during the enrolment via script, there is no script for this currently. However, you can fix it through Azure Automation after enrollment follow the link below.
Non-official, just for reference.
Or, you can check the right device name before enrollment or bulk rename the incorrect device name via Intune portal.
Hope this can help you, and if there is any update, feel free to contact me.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.