Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.
In addition to the solution provided above by @Vidya Viraktamath , I wanted to add a few more details.
Make sure the NSG associated with the Application Gateway subnet allows outbound traffic to the private IP address of your Application Service on the port it's listening on (443 for HTTPS) and also verify the NSG on the Application Service subnet allows inbound traffic from the Application Gateway subnet on the service port. Please refer this document.
If you have a UDR on the Application Gateway subnet, make sure it's not inadvertently routing traffic destined for the Application Service to an incorrect location. The route for the Application Service's private IP range should point directly to the virtual network or have a more specific route. Please refer this document.
The Application Gateway needs to resolve the private FQDN of your Application Service to its private IP address. Make sure that the Application Gateway is using a DNS server that can resolve private DNS records within your virtual network.
The presence of a custom DNS in the VNet could also cause issues. An FQDN used for backend pool members might not resolve correctly by the user configured DNS server for the VNet.
Check that the health probes configured on your Application Gateway are correctly set up and are able to reach your Application Service. If the probes are failing, the Application Gateway will mark the backend as unhealthy and return 502 errors.
Make sure the Private Endpoint for your Application Service is correctly configured and associated with the correct subnet and also verify that the private DNS zone for your Application Service has the necessary A records that map the service's FQDN to the private IP address of the Private Endpoint.
Also use the "Effective Security Rules" feature in the Azure portal to check the actual NSG rules that are applied to the Application Gateway and Application Service subnets.
Enable diagnostic logging for your Application Gateway and analyze the logs for any errors or clues related to the 502 error. Check the logs of your Application Service for any errors or exceptions.
References: Troubleshooting bad gateway errors in Application Gateway
Please refer to this document for additional reference and see if it works for you.
Kindly let us know if the above helps or you need further assistance on this issue.