Except when they walk off into the pit themselves...or was that the koopas?
Both goombas and koopa troopas will walk off cliffs, although there are extra rules for koopa troopas. In the original Super Mario Bros., red koopa troopas will turn around when at a cliff's edge, while green ones walk off. In later games, however, like Super Mario World, other rules applied, like red shells meaning that they make Yoshi spit fire.