Generally, we study waves in an ideal situation that consists of no dissipative forces. In such an ideal situation, any mechanical wave would indeed travel forever to infinity in one direction if the medium extends to infinity because there is nothing to stop it (meaning nothing causes the wave to lose energy).
However, in reality various dissipative forces act on the mechanical waves (both transverse and longitudinal waves). These forces cause the waves to lose energy over time.
You can practically observe this in water waves. Some of its energy is converted to sound energy (energy of sound waves produced in medium surrounding water) which you can hear.
Also, when we study various waves in gaseous medium, we assume the medium to be an ideal gas for simplicity. Such a gas has no intermolecular forces. But real gases in the real world have intermolecular forces which resist the vibration of particles.
Another dissipative interaction is the absorption of energy by particles of medium. As waves travels through medium particles attain some energy. 580
These particles may (they kind of always do) absorb some energy as thermal energy and pass the remaining energy to the next particle.
So, all these effects combine together to gradually cause the wave to lose energy to the extent that we are not able to detect it and finally, it ceases to even exist.
As mentioned by @OfekGillon and <PERSON>, what I have described is generally termed as damping. However, there are some other important causes of what you have asked, attenuation being one of them.
According to Wikibooks, attenuation refers to combined effect of scattering and absorption which also cause the mechanical waves to lose energy.
NOTE: Waves disappear when particles of the medium stop vibrating, i.e. stop transfer of energy through medium. The effect of this decrease in vibration can be seen in decrease of amplitude. Intensity is proportional to square of amplitude. It is the energy transmitted per unit area per unit time. So, decrease in amplitude, energy or intensity refers to disappearing of a wave.
I hope this clears any doubts in your mind. 580