When user clicks open a message in the Gmail, system automatically finds relevant ads according to the contents of the email and show them. For instance, if there is a conversation about the Resume then you will see ads related to Jobs.
Now with today's rolled out change, if system is not able to find relevant ads then other email messages are used as a input to the ad system and Gmail show relevant ad according to the contents in the other email messages. For example, let's say you're looking at a message from a friend wishing you a happy birthday. If there aren't any good ads for birthdays, you might see the Chicago flight ads related to your last email, about your Chicago's visit, instead.
This is what Google says about the user privacy:
"To show these ads, our systems don't need to store any extra information -- Gmail just picks a different recent email to match. The process is entirely automated: no humans are involved in selecting ads, and no email or personal information is shared with advertisers."Some recommeneded reads if you want to master Gmail: