You're looking at it the wrong way. Both undergrads and grad students are charged tuition by the university. This tuition is used to pay faculty, administration, operating costs, etc. Some undergrads receive full or partial scholarships. You might say they are not "paying" for undergrad, but the university is still getting paid, just from a different source. The same occurs with grad students; many of them are given research assistantships, meaning that their advisor found external grant money and is using it to pay both tuition and a stipend to the grad student. Grad students without teaching or research assistantships, such as many MBA or law programs, still have to pay tuition out of their own pockets.
Teaching assistantships are not external money, but essentially a department is saying that they have to pay someone to provide instruction, so it's cheaper to pay grad students to assist a professor than to hire more faculty. The university is still getting the tuition paid by the department.