Outside of a few [Windows 10 scenarios] and Azure virtual machine scale set automatic OS image upgrades, Azure does not currently support an upgrade of the operating system of a Microsoft Azure Virtual Machine:
https://learn.microsoft.com/en-US/troubleshoot/azure/virtual-machines/server-software-support
Microsoft does not support an upgrade of the operating system of a Microsoft Azure Virtual Machine. (For more information, see KB [4014997][3].) Instead, you should create a new Azure virtual machine that is running the supported version of the operating system that is required and then migrate the workload.