You point the DNS record for your domain (A or CNAME) to tumblr's servers. No different than pointing it at your own server.
Their web server gets the HTTP requests the same as if it was their domain.
All HTTP requests are pointed to the same document root; no virtual hosts or anything else domain specific.
Their code looks up what user has registered that hostname and shows their site.
Tumblr itself doesn't have to do anything to support custom domains except store what domain is associated with what user in their database.