Today there is a post in r/europe showing a photo of a university jail used to imprison students who broke the law in the city. It excited my curiosity so I came here to ask you about it like it seems a quite odd custom.
Yes, it's very much real (here's an image of the local Karzer at my university, it's less pretty because it was only used for a short while due to being newly built before the Karzer was abolished) It's a relic from the times where universities and their students weren't under the jurisdiction from the town they were located in. This was something that started when the oldest university in Europe - Bologna - was granted the privileges outlined in the so-called authentica habita, granting all members of the faculty and their students exemption from being tried under secular law and granting them similar protections as those given to the clergy. Depending on location, the university had its very own court responsible for judicial matters pertaining to any and all university members, or, as was also common, was subject to canon law (which curiously was compiled by Gratian, who himself was working in Bologna).
Now, students being well, students, tended to really use these privileges to their full extent (someone with more experience on things like the Swindlestock riots in Oxford might want to expand on this) - while harsher offenses could simply lead to them being expelled, minor ones like public drunkenness, being excessively noisy, breaking traffic laws, pretty much any kind of public disorder, really, still had to lead to disciplinary action, which the university had to carry out. For that purpose, German universities had the Karzer.
Even though the Karzer sounds like fun and games now, at least when you read the accounts that stem from the late period, where it was basically highly ritualised house arrest, it used to be quite serious - it literally was university jail, like you'd imagine jail to be. However, starting around the 18th or 19th century it began to be taken less and less seriously, with Karzer time being considered a badge of honour of sorts, especially for those students who were in fraternities (which, back then, was most of them).
This led to curious exchanges probably not too dissimilar to the one imagined by Mark Twain, quoted in the thread you linked. Being sentence to jail time became more of a formality than an actual punishment. Students were carried to the Karzer by their fraternity brothers and celebrated like heroes, with them drinking to his name and drinking with him after he was released. Especially past German unification, when the universities lost their special jurisdiction in 1879, the Karzer came to be considered a joke. While the university was still allowed to use it for disciplinary action, it wasn't even close to being as grave as it used to be when it was established. Karzer punishment kept being carried as far as the 1930s (most universities let it fall into disuse around WW1), but only for minor offenses that happened within the university itself, not if they actually broke the law. Past that, no university kept theirs in use for its original purpose.