From the Super Mario Wiki
Anvils are weapons similar to Thwomps occasionally appearing as hazards in various games.
Anvils appear again in the final pages in Yoshi's Story, where they are carried by the Black Shy Guys inside Bowser's Castle. If a Yoshi walks near the anvil-carrying Shy Guys, they will drop the giant, spiked anvil and crush whatever is beneath it. They appear in the levels Lift Castle, Ghost Castle and Mecha Castle.