Why does sound travel faster in solids and slower in gases?

Sound waves are a mechanical vibration, and the closer the molecules are to each other, the speedier will be the sound.

The velocity of sound in a medium is c=(k/p)0.5. Where c is the velocity, p is the density, and k is the bulk modulus (the springiness).

In solids, the velocity ranges from several km/s for Be, to a low value for lead, which has a low springiness.

Gases of course, have their molecules further apart, they are less dense, and their springiness is lossy.