Actually, the answer is the same as why most hackers do anything (write computer viruses, hack Web sites, you name it): Money.
Lots and lots and lots of money. Malware, viruses, and hacking nets literally tens of millions of dollars a year, primarily for Eastern European organized crime, where it has become one of the biggest moneymakers (ahead of traditional enterprises like drugs, prostitution, and extortion).
Gmail and Yahoo email accounts are valuable because once they are hacked, which is usually done by automated tools run from virus-infected PCs, the lists of hacked accounts are sold to spammers.
The job of spammers is getting more difficult. Almost no ISP left in the world will permit spammers to send spam through their mail servers. Botnets--networks of virus-infected computers--are remotely controlled and turned into spam relays for the bulk of spam, but it's getting harder and harder to deliver spam from infected computers any more.
One of the big tools in the anti-spam arsenal is
Sender Policy Framework (SPF). It helps block spam by detecting whether or not an email has forged or "spoofed" headers. The emails that are sent out from virus-infected computers generally do.
But Google, Yahoo, and other "big" email providers are well-known and trusted by most mail systems. Their servers include SPF validation information inside every email that is sent. If you can hack someone's Gmail or Yahoo account and use it to send spam, the spam will pass the SPF checks that anti-spam software uses with flying colors. Eventually, Google and Yahoo will detect that the account is sending spam and disable it, but by then you've already sent out a bunch...and it has a much, MUCH higher chance of getting through spam filters than spam sent in other ways does! Spammers buy lists of hacked Yahoo addresses in blocks. When one account is shut down, they automatically move on to the next.
Additionally, Yahoo and Gmail addresses offer another benefit to spammers. They can harvest the accounts to get all the owner's contacts. Most of the owner's contacts have probably whitelisted the owner and/or will know the owner and read any email that comes from that address, so the spammers can harvest those contacts, send spam to the contacts, and know that there is nearly a 100% chance the spam will get through.