Well, “necessarily” is a strong condition, but with few exceptions it’s usually cheaper to hire an entry-level tenure-track faculty member in any discipline than to pay a tenured full professor in any discipline. That said, there certainly are pay differentials by discipline, and yes, CS is toward the high end and humanities toward the low end. This reflects supply and demand in the academic market, and to a limited extent outside competition from the private sector. But in general academic salaries don’t come close to matching private sector salaries in fields like CS where there’s private sector demand. People become academics because they want to teach and do academic research; CS, engineering, law, and business faculty could almost always make more money in the private sector, but the psychic rewards they get from academic life outweigh the money.
According to a survey of 696 institutions and 162,818 full-time tenure track faculty conducted by the College and University Professional Association for Human Resources, the average full professor salary at research universities in 2017-18 was $127,433, while the average newly hired assistant professor salary was $84,345. The average for a full professor in the humanities was $100,750, while the average for a newly hired assistant in CS was $96,000, and in engineering $91,429. So the net cost reduction from replacing a retiring classicist with a newly minted CS assistant professor isn’t great, but there’s still some cost reduction. Keep in mind these are averages; salaries at individual institutions vary widely.
Also keep in mind that there’s usually a wide range of full professor salaries even within the same discipline at the same institution. Most schools give annual salary increases based on some combination of seniority and merit, and because tenure rules usually prohibit pay cuts, this is a one-way ratchet. Typically full professors at retirement age earn well above the average full professor salary at the same institution.
Of course, in our example it would save the school a lot more money to simply induce the tenured full professor classicist to retire while not making the CS hire, but if you need to make the CS hire anyway, what better place to find the money to do it?