Except - while they weren't worth that much (remember to correct for inflation, they were worth more than you think), they were worth something. In the case of bankruptcy, they were a potential asset towards paying off a legal financial obligation. In other cases, the assets were simply sold to a salvage company who had the right to dispose of them as they wished. In some cases, particularly narrow gage, the salvager counted on using some of the operable equipment to physically salvage the line. Once the track was lifted, the equipment left in the corner they scrapped themselves into either had to have a potential resale value otherwise it was just so many pounds of steel. Likewise if the rail and other track material had a higher resale value and demand it was sold as such, otherwise it just was sold for melting. There's numerous instances of a railroad offering equipment or buildings to a municipality for display, only for them to turn it down.
The last SP 4-8-2 Mountain #4367 that was homebuilt in Sacramento Shops was scrapped in Eugene in 1961 reportedly after being offered to several cities with no takers. Of 83 locos in the SP Mt class, only a tender may survive.
On the other end of the spectrum - Nevada Northern 40 survived in part because the shop crew hid it from managers. Other engines had similar stories. And don't forget the EBT! What exists today is because of the family that owned the salvage company.