Some airlines like to part company with their aircraft whilst they’re still fairly young figuring that the increased passenger appeal, greater efficiency, reduced maintenance and higher dispatch reliability will offset the higher price of a new aircraft.
However an airline in a third world country may be unable to afford to buy new, passengers are very price sensitive and local labour for maintenance is cheap, in which case buying second hand makes sense.
Back in the old days when engineering was cheap in Hong Kong, Cathay Pacific could buy a used aircraft and overhaul it to as good as new standard at a considerable saving versus buying new.
Iran is under sanctions but has plenty of oil so buying older types which no one else wants because of the fuel consumption, such as the A340 is worthwhile.