I suspect they are buying Beats because they see money in it.
I wouldn't buy those headphones, because (a) I'm 40 and (b) they're overhyped crap. But millions of spendthrift teens crave them. And if Apple can turn them (relatively cheaply) into overhyped great headphones, there's a ton of money to be made. And if this deal goes through, I suspect they think they can. I wouldn't bet against them.
I suppose it's worth thinking about why Apple might want Beats in the first place. Maybe it wants to take over Beats Music, the company's relatively small streaming service, and build it into a competitor of Spotify and Pandora. Maybe, as Peter Lauria suggests, Tim Cook wants to work with Beats co-founder Jimmy Iovine. Or maybe Apple just wants to buy a company that brings in a reported $1 billion in annual revenue, and whose flagship product is massively popular among young people. (For what it's worth, I live next to a middle school – every seventh-grader has Beats headphones.)
Others have since speculated on Beats Music (streaming service) as the reason for the acquisition. That could also be; I wasn't even aware it existed, but then as noted above, I'm 40.