A scramjet is more efficient than a rocket engine for the same two reasons that all air-breathing engines are more efficient than (chemical) rocket engines:
- Chemical rocket engines need to carry both their own oxidizer and their own fuel, whereas air-breathing engines only need to carry their fuel and take the oxidizer from the air. Therefore, for the same mass / volume, they can carry roughly twice the amount of energy, or for the same required energy, they need to carry roughly half the amount of propellant. (It's not exactly 2:1, of course, because of different densities and stoichiometric ratios.)
- Rocket engines need to carry all their reaction mass with them, whereas air-breathing engines simply suck in reaction mass at the front and throw it out again at the back. This means that
- For rocket engines, the reaction mass is finite, for air-breathing engines, the reaction mass is infinite.
- For rocket engines, the reaction mass eats into the payload capacity, for air-breathing engines, it is "free".
These points are true for all air-breathing engines, not just scramjets. Air-breathing engines, in general, are more efficient than chemical rocket engines: ramjets, scramjets, turbojets, turbofans, turboprops, all of them.
Note: I only consider chemical rocket engines here, not nuclear-thermal, nuclear-fission, or nuclear-fusion ones.
As for the comparison between ramjet and scramjet, it is actually not true that scramjets are more efficient that ramjets, as a blanket statement. It depends on the speed:
- Below Mach 4, scramjets don't even work, so talking about their efficiency makes no sense.
- Between Mach 4 and Mach 5, ramjets are more efficient than scramjets.
- Between Mach 5 and Mach 9, scramjets are more efficient than ramjets.
- Above Mach 9, ramjets no longer work, so talking about their efficiency makes no sense.
(All numbers rough approximations.)
See the $I_{sp}$ graph from the accepted answer to the related question Is the compressor required on jet engines? Can air be rammed into the turbine? for details: