It's not so much that Apple understands marketing (they use the same ad agencies as anyone else), but they understand the market.
I think a really good example of this phenomenon is the whole screen size debate. The tech press just could not understand why Apple was so hesitant to join in the screen size war and go from 3.5" to 4.0" to 4.3" to 4.7" phones. The tech press is, of course, almost entirely male. Meanwhile, more than half of the potential customer base for these phones is female, and disproportionately young females at that. Females have substantially smaller hands than males. My wife, who has no exposure to the tech press debate over screen size, lamented to me that her new iPhone 5 was great except she didn't like how the screen was bigger and harder for her to use one handed.
Apple gets it. Apple understands that teenager girls are a bigger market than male geeks and designs its products accordingly. If you think, instead, that Apple's dominance is the result of Apple being better at targeting advertisements to teenage girls, then you've completely lost sight of the ball.
Precisely, Apple understands that the women demographic is more important than the male. An observation I've noted is that of the women that love iPhones all love them due to the size and "feel" in their hands. A very visceral and physical response to a device if you ask me. They may hate the rest of the phone/company/etc, and hate here is over-exagerrating, but being able to hold your phone in one hand to use is important to many people.
Having to explain this as a guy with small hands to really big guys is annoying. But I have noticed that larger people (physically) don't mind the larger/wider phones. But their hands are actually bigger. I can't use a phone much wider than the iPhone. Once I get to the point that I have to shift the phone in my hand I feel like I'm holding a mini tablet.
I know everyone raves about the bigger devices but I can't use them for more than a few minutes. They're too wide for me, no matter how much I may want to use android I have to side with the women on this one. 3.5" width is the sweet spot for the other 50% of the population. As guys the sooner we realize that our physical characteristics influence what we buy we'll be better off.
For the record my glove size is 7.5, big for womens hands, tiny for guys.
They do have an excellent grasp of their market, but their largest demographic for iPhones are males over 25, not female teenagers. Even so, I'm sure they did plenty of UX research with a large diversity of users in order to come up with the ideal screen size and repeated this with the iPhone 5.
Counterpoint: my GF really liked her Note 2 while she had it (her S3 was stolen, but eventually recovered and the Note 2 got sent back). But I couldn't have used the Note 2, because it wouldn't fit in my pocket. Her? She put it in her bag!