The first time I watched this, having watched both Time Bandits and The Adventures of Baron von Munchhausen, I was rather shocked. The ending spirals into insanity as he's rescued, then watches his idol devoured by the papers blown from the exploding Ministry of Information, running through a madcap city, dealing with his now young, sexy, and uninterested mother, and finally, finally, seeming to find a moment of happiness, escaping with his love interest, inexplicably alive again, into the country... Where it's interrupted by the faces of his interrogator and his former boss suddenly poking onto the screen, saying that he's gone, his mind snapped by the torture. I was... frankly quite traumatized, after the somewhat strange, even depressing, but ultimately optimistic endings of Baron Von Munchhausen and Time Bandits... when I realized the truth. The only reason we think of the strange ending as being a fantasy is because the rest of the movie has been predominantly fairly realistic. But there's no reason to believe one world over another. The movie is as we perceive it to be, so if I want a happy ending for this character, escaping from the cruel, industrial hell that he lives in, and being the hero he always wanted to be, that he would've been had he been in the other movies, then why not?—Ajoxer
I'd say you hit on the actual point: even if it is a fantasy, then the ending is still happy. In his mind, he's free, and with the woman he loves. He doesn't see his prison, and he doesn't feel the torture. If nothing else, he denied them their last victory: they can't have his mind/soul. That belongs to him exclusively, and as long as it belongs to him, he is free.
When I saw that movie myself, I immediate went into a sort of Fridge Philosophy mode, thinking back and trying to pinpoint the exact moment when his mind started to go. Of course, having watched the movie The Good Night the day before added a whole new level of perspective, since they share a similar theme even though the settings, plots, and characters are completely different. Well, except that Sam from Brazil and Gary from The Good Night do have the same somewhat pacifistic/ineffectual nature.
When we see the young version of Sam's mother in the film's ending, for one brief shot Katherine Helmond is replaced by Kim Greist, who played Sam's dream girl Jill. On first inspection, this seemed like just a bit of directorial wankery. Then I realized the true implication: From the beginning, Sam's dream girl was his mother. Jill just happened to look like a young version of her.
At the end, Sam is being shuttled around endlessly to bureaucrats who read to him his long list of crimes. If you pay attention, it's apparent that everything they're charging him with, he's done!
Harry Tuttle's portrayed in dashing, swashbuckling style... but he's clearly a Sociopathic Hero, if he exists at all, giggling and killing two mooks by drowning them in their own feces.
Harry Tuttle's demise is also a mind blowing example of Fridge Brilliance; paper attaches to him and as much as he tries to shake them off they just envelop him and eventually consume him; initially I just justified it under the surreal context of Sam's insanity but then it occurred to me that Harry's demise matched his plight with the Ministry of Information - the bureaucratic regime that flooded his profession with paperwork such that it confined him and prevented him from being a natural man of action to the point where it destroyed his very being.
Tuttle's catchphrase, "We're all in this together," is Fridge Brilliance: everyone in the movie, excepting possibly Lowry's mother, is under constant threat by their own dystopia. A Meaningful Background Event in the form of a propaganda poster even implies that Tuttle's not the independent entity he claims. His catchphrase, if not something he picked for irony, is one of the government's official mottoes.
The aspect of torture is shown as a fact of life in the world of Brazil and serves as part of the film's narrative/plot, ostensibly drawn from Orwell's 1984. Yet when you consider that Brazil was written by Gilliam as a satire and as an attack on bureaucracy in the modern world, it appears to be a brilliant, explicit metaphor: bureaucracy IS torture!!
There's a SWAT team out looking for Jill, even though she's been declared dead; they eventually find and kill her. Sam should've realized that the bureaucracy is so inept and slow that falsifying the death report wouldn't be enough to save her.
Considering that information retrival charges can run you into bankrupcy in this world just imagine how student loans would work (at one point a guard urges Lowry to confess or he will have a good chance of ruining his credit history).