This happens in one episode of Golgo13. Duke Togo allows himself to be arrested so he'll end up in the same ludicrously high-security prison as his target, a crook whose old companions are worried about spilling the beans on them. Needless to say, escaping a prison that makes The Alcatraz look like a cardboard box is no problem for Golgo 13!
Lupin III knows he can do this at any time, due to the obsessive nature of his archrival, Detective Zenigata. As a Gentleman Thief, Zenigata has been trying to arrest him for years. All he has to do to go to jail is walk up and announce he's Lupin, coming to surrender.
Ladd Russo does this in Baccano!! 1934 - Alice in Jails in order to get to Huey, who was held at Alcatraz. While serving a sentence in a different penitentiary and acting like a model prisoner, he learns that inmates may get themselves transferred to Alcatraz for persistent or serious troublemaking in prison. He decides the best way to make such trouble is to systematically brutalize every other inmate in the prison cafeteria.
In Suicide Squad #6, Harley Quinn shoots up a police car outside of a police station in order to get herself arrested and taken inside the station where the Joker's skinned face is being kept.
Batman villain Black Mask's accomplice, Circe, tries to get Harvey "Two-Face" Dent to do this - return to Arkham Asylum and kill Black Mask while he's in there.
Batman also does this himself, getting himself into Arkham because he knew Zasaz, despite being locked up, was somehow sneaking out to kill people.
Deconstructed in a MAD joke regarding Prison Break. The joke points out the Fridge Logic associated with Michael's plan, saying that even if he clears his brother's name, he'll have to serve his own sentence for something he actually did.
On the occasions that The Punisher wants to be put in prison, all he has to do is walk up to the nearest police officer and show them his skull shirt.
One Lucky Luke comic book has the Daltons trying to get thrown in jail so that they can dig up a large treasure buried in the prison grounds. However, the judge turns out to be incredibly soft on crime, eventually forcing them to simply dig their way into the prison. As one of them points out, this is a complete reversal of their normal operation.
The Punisher often pulls this off, though in his case it's less committing crimes and more strolling up to the police station and surrendering. In one story he does just that when he hears Daredevil's been arrested, killing crooks while he waits for Daredevil to show up asking for help.
Fear is the Key (1972), a film adaptation of the novel by Alistair MacLean. The protagonist gets into a bar brawl with the police so he can get hauled into a courtroom where he takes the daughter of a millionaire hostage and a Car Chase ensues. The entire event turns out to have been faked by the police to give the protagonist a convincing criminal background, as the girl's father is involved with The Mafia. In the novel though the bar brawl at least is implied never to have happened.
The movie Law Abiding Citizen had a man not only get himself thrown in jail, but then got himself sent to solitary confinement. He got himself sent to solitary because he'd already dug a tunnel out so he could escape at will, cause mayhem all over the city and have the perfect alibi - all to get back at the prosecutor who took a plea bargain from one of the men who broke into his home and killed his wife and daughter in front of him.
In Lets Go to Prison, the protagonist is a convicted criminal with a plan for revenge on the judge that locked him up over and over since he was a preteen. Unfortunately, he gets his plan together a day late and the judge is already dead from natural causes. Instead, he goes after the deadbeat son of the dearly departed judge and gets the guy busted for drugs, then he deliberately gets himself arrested so he can become the deadbeat's cellmate for the sole purpose of making his life hell (he pleads guilty on condition of being allowed to serve his sentence at that specific prison). Eventually, the two are forced to bond together in order to make it through their prison stay alive.
In Skidoo, a retired hit man (Jackie Gleason) is ordered by The Don (Groucho Marx, in his last role) to get himself into prison to kill a snitch (Mickey Rooney).
In The Departed, to make Billy Costigan, Jr. suitable for use as an undercover cop, it is arranged for him to go to prison on a forged assault charge that gives him street credibility.
In Face/Off, to locate a biological bomb planted by Castor Troy, Sean Archer must take Castor's face and get planted in a federal prison to extract information on the bomb from Castor's brother Pollux. But when Castor comes out of his coma and steals Archer's face in reply, Archer actually has to carry out a real jailbreak.
Mission Impossible Ghost Protocol starts out with the team breaking Ethan Hunt out of a Russian prison. In the end, it turns out that he was actually there because he got arrested in order to infiltrate the prison and gather information from Bogdan.
In The Three Stooges short Three Smart Saps, the Stooges' fiancees' father has been framed and thrown into jail, so the Stooges elect to get themselves arrested so they can bust the old man out. Hilarity Ensues as the Stooges try to break the law and get caught.
White Heat. The undercover cop seeking evidence against Cody Jarrett specializes in this kind of assignment.
Colombiana. Our introduction to the protagonist as an adult Professional Killer involves her suddenly ramming a police car while Playing Drunk. The police put her in a cell overnight to sober up; she breaks out of the cell, kills a criminal who's being held overnight there by Federal Marshalls, then gets back in her cell as an alibi. Unfortunately the feds realise the killer had to have been in the building, so start checking into everyone held in custody.
In one of the books of the CHERUB Series, Teen Superspy James Adam's assignment is to go undercover in an Arizonan maximum security juvenile prison and engineer the escape of himself and one of the juvenile inmates. The plan is that the inmate he is helping them escape will lead them to his fugitive mother, a wanted international black market arms dealer. He does this by posing as a juvenile with a felony record, which is faked by the FBI.
In Savannah SwingsawMack Bolan discovers an elite KGB assassin is after a petty embezzler, so he gets thrown into prison. Hal Brognola creates a fake criminal record, but Bolan commits a burglary so he'll be caught by local police, in order to get close to the kid, avert the plot and find out why he's being targeted. Things go pear-shaped though when some fellow vigilantes recognise Bolan and bust him out, thinking they're doing him a favour.
He does have to try to get into an actual prison rather than juvenile hall. When the judge is about to give him a reduced sentence, he flips out in court and attacks a reporter, causing the judge to lose all sympathy.
The Distant Finale of the series is a short story where the Rat, as an old man, apparently loses his touch and gets arrested and imprisoned. It turns out he's still got it, and let himself get caught as the first step of a plan to bust an old friend out of the prison.
In his final novel, Quiller discovers a witness who has evidence that can bring down a high-ranking boss of The Mafiya has been thrown into The Gulag. He gets himself sent there too (though only by faking the conviction papers) even through no-one has ever escaped before.
Happens in Warbreaker when Vasher gets arrested in order to get Breath from a captured rebel.
Discworld has Done-It Duncan, who'll confess to anything in order to spend the night in jail, where he's safe from other criminals and gets something to eat. He almost never actually did it, and the Watch put up with him because he inadvertently gives them information about the crimes.
The entire premise of Prison Break. A man is Wrongly Accused and his brother, Michael Scofield, commits a bank robbery so he'll be caught and thrown into the same prison (Scofield pleads 'no contest' on condition he's sent to a prison near his home) to help him escape. It helps that Scofield designed the prison, and the design is now tattooedonto his body.
An early episode of The A-Team had an episode where Hannibal, BA and Murdock tried to get arrested as part of the plan to get thrown in jail to break up a illegal prison fighting ring.
The Sarah Connor Chronicles. Vick finds one of his targets has been thrown into jail, so he follows suit by the simple method of walking up to a group of police officers and punching one of them. Of course being a Terminator he can get out at any time just by knocking the cell door off its hinges. Notably, this one manages to get around the big issue of being sent to the same area as the prisoner in question, because the target is in temporary holding, just like Vick would be when assaulting a cop. Once he's inside, he can literally just rip the doors off the walls until he finds his target.
In Burn Notice, Michael asks to be put in prison for a week to protect a friend of Sam. This ends with a prison riot, and the man who wants Sam's friend dead being broken out of prison, and set up to go right back. Mike manages to get in by use of the two FBI agents who owe him a favor from a previous episode.
In an episode of Due South, a key witness is behind bars and Fraser's partner is jailed for contempt. Fraser gets himself arrested to join them and be in position to protect them. He's such a straight arrow that he can't bring himself to shoplift a candy bar, and his police friends have to plant it on him.
Chris Ryan's Strike Back. John Porter gets arrested in Zimbabwe for dealing in illicit diamonds so he'll be thrown into a high-security prison where a British national is accused of trying to kill Robert Mugabe. Porter's job is to break the Brit out, interrogate and then kill him.
Done in the Mission: Impossible episode "Old Man Out". Of course, the IMF stacks the deck in their favour to get the result they want. Rollin is arrested for pickpocketing right outside the prison, and the arresting officer is Dan Briggs disguised as someone high-ranked enough to order the prison to hold him till he can be charged.
One episode of Batman had The Penguin try this after acquiring samples of various rich people's handwriting, because a forger has been imprisoned next to his usual cell.
In Veronica Mars, Logan takes a tire iron to a police car in order to get thrown into a holding cell...with the guys who nearly raped Veronica. We get a nice Oh Crap look from them, and the scene ends.
In Justified Boyd Crowder assaults a US Marshal in a federal courthouse in front of dozens of witnesses. He assaulted a federal agent on federal property specifically so he would be sent to the federal prison rather than county jail. Once inside he bribes a crooked guard to be placed in the right cell. He is trying to get close to Dickie Bennett who is in the prison awaiting trial on federal charges. Raylan figures this out and tried to thwart the plan by having the charges dropped and Boyd released.
The Practice: To avenge a deceased relative, a man kills the hitman and arranges to serve his sentence at the very same prison the one who hired the hitman was serving time for another crime.
Done by Max in Get Smart to get back a microfilm he'd planted onto a tooth of a convict being sent to prison.
Law & Order: SVU: Olivia knows that one of the corrections officers at Sealview Women's Prison has been raping and abusing inmates (as well as the 14-year-old daughter of at least one of them). So to catch him, she goes undercover as a woman named Katrina Rae Lewis sent there for a theft or something, complete with a fake past-record of an abusive father and an abusive ex-husband. She ends up getting sexually-assaulted by that CO.
On My Name Is Earl, Randy misses Earl so badly that he takes the exam to become a prison guard...and since he scored at least 50%, he passes. Though he's such a bumbling idiot that just like on the outside, Earl ends up protecting Randy instead. (Sometimes from other prisoners, sometimes from Randy himself.) Before that, Randy stole a car and parked it on a median strip hoping to get caught, but he never did.
In the same series, Earl's old friend Glen kept getting himself sent back by stealing cars (or by sabotaging his chances at parole), because people were so afraid of him.
On Orange Is The New Black, Taystee gets out of prison, but she winds up getting sent back within a few weeks. Turns out she committed a crime on purpose, because (despite her immense talent and skill) she was unable to adjust to life on the outside again.
Fargo: In "Eating the Blame", Lester punches a cop in order to get arrested and away from Numbers and Wrench. Numbers and Wrench later stage a bar brawl and get arrested and placed in the same cell as Lester.
A sidequest in The Elder Scrolls IV: Oblivion involves getting yourself imprisoned to gain the trust of an inmate, who you are told has hidden a stash of treasure somewhere.
At one point in Baldur's Gate II you have to get yourself sent to Spellhold - which is actually the local asylum, but it plays out similarly. The easiest way to do so is to tell the local Lord you must be deranged because you travel with Minsc. After being subjected to Minsc's conversation for a few minutes he wholeheartedly agrees and sends you there forthwith.
This is how you get to join the terrorists in Splinter Cell: Double Agent.
Excelsior Phase One Lysandia: The PC must speak to a political prisoner, and so when the guards mention they're looking for a murderer and ask if the player knows who he is, the PC turns himself in.
Grand Theft Auto II features a mission where the Rednecks want the protagonist to shoot up Alma Mater Prison from the inside. The player has to get arrested while selling moonshine to get in.
In one episode of Darkwing Duck, Darkwing pretends to be a supervillain so he can get thrown into supervillain prison. Getting arrested turns out to be ludicrously difficult, however. Made especially silly since there is no reason the police would be unwilling to assist him in his infiltration.
Young Justice does this with a twist: a collection of ice villains all get arrested so that they can help with a break-out. The heroes get clued off when this involves Mr. Freeze suing to be considered legally sane and Icicle Jr. suing to be tried as an adult.
King of the Hill - Hank gets himself arrested to talk to Bill, who'd been put in jail on a petty charge after getting estranged from the gang. Humorously, Hanks's first idea is to jaywalk in front of a cop (he waits for the light to switch and then walks), assuming this is enough. Finally, he decides to give one of their cars a light bump with his truck. Of course, their reaction is immediate and angry — he's in jail quickly.
There's a variation in another episode where Boomhauer had been put into a psychiatric hospital after falling asleep tubing and showing up in the city in a sunstroke-induced rambling state, clad in a Speedo and algae. His friends each feign craziness to get admitted and spring him, unaware that he could leave anytime he wanted.
Boomhauer was allowed to leave as the 24 observation period was complete, Dale could leave because he had snuck in and wasn't actually a patient (although the doctors recommended he keep taking his meds), and Bill had voluntarily checked himself in so he could leave when he wanted.
In one episode of COPS, Rock Krusher walked into the police station and tried to rob the place. He was easily apprehended, but what he really wanted was to be sent to prison as part of the Big Boss' latest crooked scheme. Luckily for him, he actually sort of likes prison life.