This is a complicated business which I will simplify a bit.
Heating an object causes its constituent atoms to randomly vibrate more vigorously. In so doing, the atoms are continuously exchanging kinetic energy back and forth between each other and so the bonds that connect those atoms are continually being exercised as well. So at any given instant in time, the total vibrational energy in the system is shared between the kinetic energy of the vibrating atoms and the potential energy of the distorted bonds between them.
This means that the system's capacity for absorbing heat energy per unit mass will depend on the atomic mass and on the exact nature of the bonds that hold the mass together. Those bonds are chemical in nature and can be ionic, covalent or metallic in a solid, and in a liquid they will be completely different- with the possibility of things like van der waals forces coming into the picture. Then in a gas, all of those considerations disappear and instead the gas atoms bounce off each other like billiard balls because those chemical bonds, whatever they might be, are absent or nearly so.
Note also that in a solid held together by metallic bonds, the outermost electrons are delocalized and hence capable of vibrating about through the atomic lattice as if they themselves were a sort of gas. This means that in a metal, the conduction electrons will make a significant contribution to the heat capacity, which you will not see in a solid that is held together by covalent bonds, where the bonding electrons are immobilized.