Basically they perform a query for MX record of the domain, following your question, for gmail.com:
alphamikevictor@ges01:~ > nslookup -query=mx gmail.com
Server: 194.179.1.100
Address: 194.179.1.100#53
Non-authoritative answer:
gmail.com mail exchanger = 30 alt3.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 40 alt4.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 5 gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 10 alt1.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 20 alt2.gmail-smtp-in.l.google.com.
Authoritative answers can be found from:
alt3.gmail-smtp-in.l.google.com internet address = 64.233.189.27
alt4.gmail-smtp-in.l.google.com internet address = 173.194.72.27
alt1.gmail-smtp-in.l.google.com internet address = 64.233.165.27
alt2.gmail-smtp-in.l.google.com internet address = 74.125.200.26
For each authorized SMTP server you have a weigh so Yahoo's MTA will try to deliver to gmail address using this servers:
- gmail-smtp-in.l.google.com
- alt1.gmail-smtp-in.l.google.com
- alt2.gmail-smtp-in.l.google.com
- alt3.gmail-smtp-in.l.google.com
- alt4.gmail-smtp-in.l.google.com
You can read more about MX record at WikiPedia http://en.wikipedia.org/wiki/MX_record