It’s up to the DM’s discretion.
Notably, a light hammer is a simple melee weapon that deal 1d4 bludgeoning damage and has the light and thrown (20/60) properties.
Per Improvised Weapons (PHB page 147),
Often, an improvised weapon is similar to an actual weapon and can be treated as such. … At the DM’s option, a character proficient with a weapon can use a similar object as if it were that weapon and use his or her proficiency bonus. … An improvised thrown weapon has a normal range of 20 feet and a long range of 60 feet.
So if we assume that the hammer in the adventuring gear table is not a light hammer in the weapons table, then the only real difference between the light hammer and an improvised weapon is that, for ranged attacks, the light hammer can use a character’s Strength modifier for the attack roll and damage, while the improvised weapon would need to use Dexterity.
The sledgehammer would either be an improvised weapon, or looking at the weights (which is not a criteria for the DM to consider), a greatclub or maul. The DM could also just choose to let the sledge hammer represent any other weapon.
The hammer is also a component in several tools, according to the optional rules in Xanathar’s Guide to Everything: Carpenter’s Tools, Cobbler’s Tools, Jeweler’s Tools, Leatherworker’s Tools, Mason’s Tools, and Smith’s Tools. For Jeweler’s Tools it specifies a “small hammer” and for Leatherworker’s Tools is specifies a “mallet”, but I have included them in this list for the sake of completion.
The hammer is additionally included in the Burglar’s Pack (PHB page 151), so it would be reasonable to conclude that they are used to destroy small or fragile objects, such as a window.
This next section is not based on game mechanics, but just describes how a hammer might be used by real-world artisans. With Carpenter’s Tools, the hammer seems to be used to hammer nails into place, and as a way to apply force to a chisel to remove wood. The Cobbler’s Tools and Leatherworker’s Tools seem to have included it as a way to compress or flatten the thread and leather. For Jeweler’s Tools and Smith’s Tools, the hammer is used to shape metals (cold for Jeweler’s Tools, and hot for Smith’s Tools). For Mason’s Tools, the hammer seems to have been included as a way to apply force to a chisel to chip away stone.
Per Objects (DMG page 246),
…given enough time and the right tools, characters can destroy any destructible objects. Use common sense when determining a character’s success at damaging an object.
Per the Sledgehammer Wikipedia article,
Sledgehammers are often used in demolition work, for breaking through drywall or masonry walls. Sledgehammers are seldom used in modern mining operations, particularly hand steel. Sledgehammers are also used when substantial force is necessary to dislodge a trapped object (often in farm or oil field work), or for fracturing concrete. Another common use is for driving fence posts into the ground. Sledgehammers are used by police forces in raids on property to gain entry by force, commonly through doors. They were and still are commonly used by blacksmiths to shape heavy sections of iron.
Ultimately, the Adventuring Gear section on page 148 of the PHB may say it best,
This section describes items that have special rules or require further explanation.
So by virtue of the fact that the hammer and the sledgehammer lack special rules or further explanation, they function as they would in the real world, at the DM’s discretion.
With this in mind, I think a common sense ruling would be that a hammer functions as a light hammer as described in the weapons table, and a sledgehammer can be used to demolish structures made from wood or brick, but not necessarily natural stone formations such as cave walls. That is common sense to me, but may not be common sense to another DM, so as usual it’s “per DM’s option” on how effective these pieces of gear are in any given situation.