I assume that you are using SSO between the sites.
So when closing an account in the main site it can query the forum using a GET to /u/by-external/{external_id}.json to retrieve the forum account, and then use the user_id in the response to issue an subsequent request closing the forum account.
I honestly don’t know how it was done, I’m just a forum admin, but thank you - I will pass this information on to the fellow who does that kind of thing.