The responding server, acting as a gateway/proxy, got an invalid response from a further server it depends on (Bad Gateway).
Where you see it
In the status line of a SIP response, often with Reason and Warning headers that say more.
What to check
Check the further server this one depends on for the actual failure.
Read the Warning and Reason headers of the response and the Via/Server of the node that sent it.
Got a trace with SIP 502 Bad Gateway? Drop it in the analyzer: it finds the step that really failed first, which node sent the code and what to ask the other side. Captures, test-system PDFs and vendor exports. 5 free analyses a month, no sign-up.