They don't attend classes after ~2 years, mostly operate independently besides consulting with their advisor, don't take anywhere near a professor's salary, teach or TA classes, act as lab technicians, and bring in money through grants.
The costs are mostly upfront in the form of providing the necessary research facilities to attract research-oriented faculty and students, and the administrative staff needed to ensure compliance with grant terms.