It’s more of an economics question than anything. AC-3 is gentler about modifying the source for the sake of better compression. Here’s the tradeoff:
Delivery services like iTunes and YouTube want the data rate as low as possible for a “good enough” sound because they pay for network bandwidth. So, at 128kbps and lower, AAC can sound better than AC-3 in many cases. (“Sounds better” doesn’t imply it “measures better” on a graph.) The abrasive reduction of AAC helps the “meat” of the sound fit into the tiny 128kbps allocated to it. Meanwhile, AC-3 isn’t as aggressive about shaving the “inaudible” range, which leaves the overall sound (meaning the recognizable core elements) to be compromised to fit the 128kbps cap.
However, as soon as a decent bitrate is given to both codecs, AC-3 pulls ahead for a clear win. The transition is somewhere between 256 and 384kbps. But no delivery service wants to pay 2x to 3x the network bandwidth price for a quality difference that the average consumer wearing ear pods in traffic will never notice.
Regarding compatibility, AC-3 is older than AAC and baked into a lot of standards. If a device supports AAC, there is a 99.9% chance it also supports AC-3.
Here’s where the economics get dumb, though. Opus is arguably better than all of them (AC-3, AAC, MP3). Even YouTube uses Opus for its high-quality VP9 encodings. However, Opus can’t be put in an MP4 container, so a lot of applications won’t use it. What’s dumb is that Opus fits in a Matroska container just fine, and Matroska is free and open source too. So we would think that every penny-pinching corporation (read: Apple) would be all over MKV+Opus for audio delivery. But nope. And I have no idea why not, except for “Not Invented Here Syndrome”.
MP3, being older than AAC, has a less sophisticated and gentler psychoacoustic model than AAC. Given sufficient bitrate, MP3 will actually sound better than AAC. At low bitrates, AAC probably wins again.
For high-quality audio encoding in FFmpeg, this wiki is a gold mine of information:
Encode/HighQualityAudio – FFmpeg
Basically, the popularity of AAC comes down to “make it sound good enough that nobody complains about music at 128kbps”. The popularity is forced down from service providers dodging network fees rather than forced up from consumers demanding quality. Simple as that. “Audiophile quality” was never a design target of AAC regardless of what the marketing department says.
Also regarding forced-down popularity… I could be wrong about this, but I recall thinking that AAC enabled some newfangled digital rights management options that gave service providers more control over distribution than AC-3 did. Obviously, the providers would opt for AAC over AC-3 to protect their cash flow. I’ve never used those options in my encodes, so I’m not familiar with all those details.