Some significant costs come from the massive scales the classes are taught at. This semester, the first required CS lower division class has 1800 students (https://classes.berkeley.edu/content/2022-fall-compsci-61a-0...) and an upper division DBs class has 600 students. (https://classes.berkeley.edu/content/2022-fall-compsci-186-0...).
It takes a lot of TAs to handle student support, which doesn't scale well in practice. The class I teach publishes lots of videos and documentation about how to do the labs, projects, and homeworks, and we also have a forum where students can (to a reasonable extent) help each other out with common questions. However, the classes teach a lot of stuff really fast and you need a lot of TAs doing things like office hours to help students who didn't understand the speedy lecture, or have a particularly nasty time trying to debug an error.
One particularly difficult thing about this scaling is that students typically need TA help all at once. Office hours right before midterms and project deadlines have many students and more bodies are needed just to have good handling of "peak" times
Another aspect of TA cost is that TAs are paid significant amounts of tuition remission for their work, and the department has somewhat of a mandate to ensure any graduate student who wants to TA can get full tuition remission from a 10 hour position or higher (I'm guessing this is somewhat of a symptom of skyrocketing tuition and inadequate aid being foisted on the department to deal with). The department used to get around this by hiring tons of undergrads at an 8 hour level so they wouldn't get remission, but they were sued and paid out millions in backpay as well as paying all TAs a scaled remission based on their hour count. (https://www.insidehighered.com/news/2020/01/16/arbitrator-sa...). Generally an 8-hour TA gets paid around $40 an hour after remission and a 20-hour TA gets paid around $50 an hour. [very rough math read the other comment for harder numbers]
-Am a TA, speaking for myself
A 20 hour TA is paid ~$2250/mo for approximately 4.5 months per semester, plus ~$7000/semester in tuition remission (so ~$17k). $350 is the total cost for the whole semester per student. 17k/350 is about 50 students per TA, which sounds about right (and even that is a higher than ideal ratio). There are other costs too, but these are the some of the highest.
(u)GSIs at Berkeley are paid particularly well compared to other schools, I think in large part due to the TA union (UAW 2865).
For tuition remission, it’s only the in-state amount, even if you’re out of state.