The problem with this is the judge is taking it upon himself to decide there is no proper basis for such a penalty, when it is clearly intended as a penalty - a disincentive to terminate the contract.
Honestly, you could probably argue these fees violate anti-trust law in the US if you get the right US District Court to agree with you that these fees are less about subsidized phones and more about preventing customers from switching services. The cell phone companies have always resisted anything that made leaving them easier (phone number portability comes to mind). There are plenty of ways to make these fees more legitimate, as in the prorated fees used by the other major providers. This is less likely to draw legal complaints.
What is next? A court reviewing a software license agreement that has a large penalty clause in it? It seems that a "penalty" that is not identified as a penalty but stated to the customer as a cost recovery, a pro-rated subsidy or something else would be a problem. But every cell phone agreement I have seen says it is basically a penalty.
Yes, but the penalty has to still conform to law. Just because you put something into a contract does not make it legal. The legality of contract clauses from cell companies and software makers (since you brought them up) have been contested and in some cases defeated in court as being unfair or out right illegal.
This said, the contract is silent on the purpose of the fee; however, the cell service providers have states repeatedly it is a means to protect their subsidies of the phones. As I stated above, the court is seeing this for what it is, total bullshit. So to recap, a contract does not make that which is illegal legal and a non-prorated termination fee does not stand up well when your main argument is cell phone subsidies cost money.