I've just deleted an email on the Gmail website. It was instantly deleted in Thunderbird as well. How does Thunderbird do this? I thought e-mail uses a request-response mechanism with only occasional checking of the inbox. Does it just poll that quickly, does it have special behaviour for Gmail, how does this work?
IMAP synchronization is always a request-response meganism, exchange however is not.
Exchange can be a request-response meganism, but it can also be a "notify me upon arrival" aka push meganism.
Since gmail uses exchange email can be synched the moment something changes if setup correctly.
Once thunderbird knows the serverside has changed, it requests a local refresh. Depending on how it is setup, either it can just refresh the email listing, or it downloads the necessary changes (depending if there's a cache enabled or not).
When connected to an IMAP mail server, Thunderbird uses the IDLE command to subscribe to change notifications. Using it will cause the server to start sending notifications every time the current folder's contents change in any way.
Although IMAP is primarily request-response, it does also allow the server to produce various "untagged" messages at any time, e.g. in-between the tagged command and its result, or even when no commands are waiting.
(Though as noted in the abstract of the IDLE RFC, the baseline protocol did not specify this adequately enough, so invoking IDLE has to temporarily switch to a dedicated "wait for live updates" mode instead. I think Thunderbird may be using one connection dedicated for idling on the current folder, and another for regular message retrieval commands.)