There are many contributing factors to this problem.
The Shuttle was designed in the 1970's and technology has matured since then. Additionally, the issues the Shuttle ran into (While in truth may have been predictable at the time) are now more obvious and a new design can try to avoid them.
Consider the simple case of the heat shield on the Shuttle. It was composed of 10's of thousands of small tiles. It was not clear they could make large tiles, of the right shape, that could handle the bending loads and whatnot. But that added a monstrous manpower cost on refurbishing the orbiter after every launch. You saw that NASA tried replacing some of the tiles where they could with larger blankets later in the program.
SpaceX went with a known workable system (PICA) refreshed for the new century, and used fairly large pieces. (Also a capsule is much smaller to coat than something the size of the Orbiter)
The engines on the Shuttle were top of the line, possibly highest performing engines ever built and used in production. But along with that comes maintenance costs which again were being mitigated somewhat at the end of the program with various upgrades to the SSMEs.
SpaceX went with the most reliable design they could find in the Merlin family, a pintle injector and spent a lot of time and effort on making the engine affordable and performant. They also iterated faster. While it is true elements of the SSME were upgraded over the life of the program, the Merlin family progressed in a much shorter time from the Merlin 1A, 1B, 1C, and 1D with a further uprating of the 1D pending soon.
The SSME are in the 660Klb thrust range, whereas the Merlin family started in the 70Klb range and has upgraded to the 195Klb (and on its way higher again with the Block 5 Falcon 9), which is a much simpler problem, and easier to design, and easier to reuse in theory.
Consider size. The STS system is huge, with 7 million lbs of thrust on liftoff vs a Falcon 9 with only 1.3 million lbs of thrust. Obviously mass of the system is vaguely similar, since you need a T/W of greater than 1 to liftoff. (Else you sit on the pad burning propellant).
SpaceX's system is much smaller, and thus much much easier to recover. Consider the problem of recovering a capsule (Dragon) vs the Orbiter. Then consider reuse. (Which to be fair, SpaceX has yet to reuse a Dragon capsule, regardless of plans to do so, Edit: 2 years later, 2 Dragons have reflown and the remaining 10 CRS missions are expected to use reused Dragons).
From a design decision the choice of wings vs vertical landing is a huge differentiator. Only time will tell if SpaceX made the right choice. NASA clearly did not make the right choice with their overall approach. (SNC would argue that wings can be done properly, time would tell, but not clear they will ever launch). (Edit: 2 years later they have landed 23 first stages without wings pretty much without fail. So probably a good design choice.)
The Shuttle needed a standing army of something like 24,000 people to maintain the system. SpaceX entire employment is still under 5000. Consider the cost of salaries for 24,000 people vs 5,000 and divide that over the number of launches a year. This is a large contributor to system costs.
For political reasons the Shuttle was built across many states, much like the European Ariane 5 is built. This way different senators and congress-critters would be willing to vote for it, as it provided copious numbers of jobs in their districts. This is a recipe for inefficiency. As has been shown by those two programs.
SpaceX builds almost everything in one site (Hawthorne, CA), tests in a second (McGregor, TX), and launches from a third (LC-40). (Soon to be fourth (LC-39A) and fifth (Brownsville, TX). For Polar orbits they launch from Vandenberg Air Force Base in California (LC-4). When they discuss their next generation launcher, they suggest they plan to build and test it next to the launch site. Mostly because it will be too big to transport.
I could probably go on for longer. Suffice to say this is comparing peanuts to watermelons.