There's a few large factors at work.
1. Solid designs. Like it or not, Samsung simply managed some good hardware. It didn't really figure things out until the Galaxy S (which arguably was 'cheating' given its origins), but it hit its stride pretty quickly. Both the S series and other major phones have at least been good enough, if not great.
2. Copying Apple. Software patents are a murky area, but there's no mistake: Samsung purposefully imitated the iPhone's design for a couple of years. The Galaxy S is a cosmetic clone of the iPhone 3G/3GS, and both the S II as well as a number of follow-ups weren't that radically different. The software interface was tailored that way, too, and Samsung hasn't stopped copying on that front (S Voice is designed to mimic Siri, Wallet replicates Passbook).
3. Sheer financial clout. Samsung was already pretty big when it got into Android, and it has had little trouble throwing massive resources at both developing and marketing devices. Apple, LG and Sony could do that, but few others could manage it.
4. Designing and making its own parts. This ties into number 3, but it's worth breaking out -- Samsung can both invent and build its own CPUs, displays and memory. That means it not only gets the tech it wants whenever needed, but it isn't at the whim of outside suppliers. Apple has the advantage of designing parts, but it still needs someone to assemble them.
5. Missteps from rivals. HTC floundered around in 2011, and 2012/2013 haven't been much kinder despite a better strategy. BlackBerry, Nokia, Palm and others also made it easier, since they were still reeling from the blow dealt by Apple. And a lot of other mid-tier phone makers (Sony, LG and others) simply didn't have iconic designs that would sway the public at large.