15GB of free email service to 400+ million people costs a little bit of money to keep running. I'm going to go with the premise that advertising helps fund the cost of keeping this service up and running.
Automated scanning is inherent in allowing gmail to be free. You submit to this when singing up for the service. 3rd party users emailing a plaintext email across the internet also have no expectation of privacy, just like mailing a postcard to someone across the world.