It is purely economics. Almost anything can be repaired but for a price. The airline, owner (leasing company or bank), and the insurance company all determine what is the most reasonable and cost-effective course of action.
Also depends on an airline's fleet plans. If the fleet type was being retired or removed, then they wouldn't bother to repair the aircraft.
Engines, systems, doors, tails, and even wings can be replaced or repaired. However if there is significant bending to the fuselage or damage to the pressure bulkheads the aircraft will be written off.
"Damaged beyond repair" all depends on the extent of the damage, what parts need to be repaired/replaced, and the amount of labor required to repair.
A newer aircraft will often be repaired since it still has substancial value. The bar can be much lower on an older, fully depreciated, and paid-off aircraft.
This is often why you will see newer aircraft repaired, while with an older aircraft even a minor issue will send it off to retirement. An example of such was the NW
DC-9-50 up in MSP
a few years ago that lost braking power and collided with an Airbus. The damage to the DC-9 was repairable, but expensive especially for a 30 year old aircraft. Wheras similar, if not worse damaged occured to a NW
757 a fews ago in LGA
but that aircraft was repaired and returned to service.
727 where its wing sheared into the side of a NW
DC-9 lost in the fog while taking off in DTW
in December 1990
There was a E-170 in CLE
a few years ago that suffered significant damage to the forward fuselage during a runway incident in a snowstorm.
A Mesaba Saab 340 that was significantly damaged when a hangar collapsed from high winds in a thunderstorm in DTW
back in 2000; required new horizontal and vertical stabilizers I believe.
The Express I Saab 340 that rolled into a concrete drainage ditch in MEM
, aka the "ditch witch"