most of the time it is related with NSG issues
Check the NSG associated with your VM's subnet, ensuring the following outbound security rules exist:
- Allow port 80 (HTTP)
- Allow port 443 (HTTPS)
- Allow DNS traffic (port 53 UDP and TCP)
In addition
- Ensure your VM's subnet has a valid default gateway configured for routing traffic outside of the Azure Virtual Network.
- Verify that the VM has appropriate DNS servers configured that can resolve internet domain names. You can use Azure's default DNS or reliable public options like 8.8.8.8 or 1.1.1.1
Also here is the official troubleshooting document by Microsoft
https://learn.microsoft.com/en-us/azure/virtual-network/troubleshoot-vm-connectivity