Court fees are not always covering all costs, and fines don't fill its own coffers
Besides wages and electricity, the courtrooms run a considerable maintenance and construction cost. The amount each case taxes the system depends on the complexity and involvement of the court, and who gets the fees., so let's break it down into rough divisions.
Trafic court-style can break even... for the government.
Let's take a typical traffic courtroom and paint a scene.
There's the judge, their Bailiff and stenographer. There's also a traffic enforcement officer that is to testify about the tickets. That's 4 people's wages and electricity to account for that ultimately end at the government's bill: three via the court and one from general police. Add to that the courtroom building and its maintenance, as well as the traffic enforcement that runs before that. Let's account that all in bulk for a total of... let's say at the top maybe one thousand an hour at the lowest level. Let's say they manage to run through 6-10 cases an hour, each resulting in a fine that averages to 100 units of currency. That's 600-1000 bucks into the coffers, so maybe breaking even. But it's not into the court's coffers, but those of the government's fines division. It doesn't subsidize the court, so it's a tax on the funds allocated to the courts, while maybe running a slight profit for the government.
Small Claims Court tries to break even for the court.
Small Claims Court is similar in setup to Traffic Court, but with both sides being civil, filing fees apply. Those fees generally cover the costs of an average small claims duration in front of the judge, and these fees do go directly to the court, so Small Claims Court generally is cost-neutral.
larger Civil cases try to stay mostly cost neutral for the court.
In a civil case, filing and courtroom fees apply. Filing fees are usually per filing, courtroom fees just about cover the maintenance and maybe the stenographer or clerk of the court. In a typical civil case, the party's lawyers' cumulate to at least one to two magnitudes more than the court gets in various fees. This is most visible when a case with fee-shifting is litigated - copyright cases are the best example here.
In a fast case where people just want a judge's signature (e.g. "amicable divorce"), the court can maybe run a (slight) profit, but usually, such a case is neutral, though in high profile or complicated cases, it's costly to the system.
Also, note that people filing their cases in forma pauperis usually can skip court fees, resulting even in small cases at times running a loss.
Criminal Trials are very costly for little (financial) gain, or even more costs.
In a criminal trial, the costs running by the government are extreme: The basic setup is multiple bailiffs, the judge, the state attorney, multiple investigators, and experts, all of them ending on the government dime one way or another. Think in thousands per hour of hearings, about halfway split between the court itself and the prosecution, possibly adding the costs of a public defender and detainment.
In contrast, the possible outcomes are a fine for the benefit of the government's bucket, that maybe might sum up to about the amount spent, but the longer (=complicated) the trial is and the higher the public interest in it, the less such payment is likely to cover costs. Again, any fine is not ending in the court's coffers, but with the treasury. Also, detainment time does not add anything to either coffer but instead costs even more. However, detainment bills the government, not the court's budget.
Note that only in a few systems a criminal defendant is forced to pay court fees. In fact, some countries, like germany, do repay the defense's attorney's costs and missed wages for court dates if they are found not guilty.