Look up an old series called America's Dumbest Criminals, and watch it to see more examples of this than you can count.
A lot of people have picked a fight with someone else, only to find out after a good beating that person is a soldier or a member of law enforcement and is trained professionally to kick someone's ass.
Tiger Beetle larva feed on ants, and the Methocha wasp looks like an ant. When the larva attacks, the wasp wriggles out of the larva's grasp, paralyses the larva and then lays its eggs, which hatch and devour the larva alive.
The Portia Spider will go to another spider's web and tap on it, most likely imitating a trapped insect. When the spider approaches, Portia rushes it, then quickly kills and eats it.
Wasps of the species Lasiochalcidia igiliensis will jump into an antlion pit. When the antlion larva tries to attack it, the wasp lays its eggs, which hatch and devour the larva alive.
The Alluring Anglerfish and other predators that use the strategy attract small fish that think their lure is just a piece of food, when it's actually a giant fish. Or a matamata turtle.
In a particuarly amusing example of this trope, two yobs attacked a pair of crossdressers only for the crossdressers to turn out to be a couple of cage fighters in fancy dress. Full story here (Wayback Machine link).
Somali pirates attacked a French navy command ship, mistaking it for a cargo ship, leading to the swift arrest of the pirates.
Somali pirates in a small skiff fired on what they (presumably) assumed was an unarmed freighter. The US Navy guided missile frigate Nicholas promptly returned fire with its deck-mounted, water-cooled, .50 caliber machine gun. (The pirates were captured, their ship sunk, and their "mother ship" subsequently tracked down and also captured.)
In 1993, somewhere in the Pacific, two pirate boats fired machinegun warning shots in the direction of unidentified dry-cargo freighter. And got an auto-cannon warning shot in return, which dissuaded them from trying to board a vessel that's supposed to carry 440 marines. It was Nikolai Vilkov — Russian large landing ship. Being a remake of civilian project it resembles a freighter◊ with its big crane.
There's a case mentioned in one of John Douglas's true crime books where a serial killer broke into a ranch house and assaulted the couple that lived there. As it was a ranch house on a ranch, and in Montana no less, the killer should've at least considered the possibility that the residents would keep guns at home. Douglas cites it as one of the few known instances in which a serial killer got killed by his intended prey in real life.
Dressing up policewomen like Ms. Fanservice and sending them out to troll for johns is standard practice for vice squads worldwide. Muggers and psychos occasionally fall for their act, and get snapped up by the decoy or her backup.
This is the entire basis of pedo-hunting, whether by the FBI or Anonymous. You pose as a gullible young girl, wait to be solicited by a child molester, track them down, and either arrest them or just ruin their life.
In the late Roman Republic a young Upper-Class Twit, who went by the totally innocuous name of Gaius Julius Caesar, was captured and held to ransom by some Pirates. While being held prisoner on the ship, the personable Caesar befriended the pirates, and made jokes that when he was ransomed he was going to come back and kill them all. The pirates laughed at their captive's great sense of humor. Later, they found out he wasn't joking.
In 1890 the three Dalton brothers and two henchmen came riding into Coffeyville, Kansas in order to gain fame by robbing two banks at once across the street from each other. Of course there were problems with this scheme notably that before their job was done word got out among the townsfolk. And a typical Western town had a lot more than five people, and an awful lot of guns.
Jesse James came to grief trying to rob a bank in Northfield, Minnesota in the 1870s. Unfortunately for Jesse, he had forgotten that he was no longer in his usual hunting grounds of Eastern Kansas/Western Missouri...and the locals not only did not include any sympathizers of his, but had their life savings in the bank he was targeting and no sense of humor about losing those savings. Oops...
Some young men were routinely killing dogs in their neighborhood and killed one small Labrador. The owner came home, pursued them in his car with a gun, then held them at gun point until the Texas Rangers appeared and arrested them. The men threatened the man who had held them at gunpoint, saying he did not know who he was messing with. The man then had the Texas Rangers reveal to the men who had killed his dog that he was Marcus Luttrell, an ex-Navy SEAL, who had won a firefight against roughly 80 Taliban fighters and was the only survivor of the battle, after dispatching every enemy fighter.
Two "tough guys" tried to robChuck Norris with knives, under the assumption that what he did in Walker, Texas Rangerwas all fake. The two ended up with arms so broken that bones were sticking out. The police didn't even handcuff them, partly out of concern for the thugs' injuries, and partly because they were laughing too hard to get the cuffs out.
Shooting Back recounts an incident where some Islamic terrorists tried to shoot up a church, presumably expecting that they'd be able to slaughter people without resistance. Much to their surprise, Charl van Wyck returns fire, thwarting their attack.
An example out of Ferdinand von Schirach's Verbrechen (a book of cases he precided over as a lawyer). Some skinheads decide that a wimpy looking man in a neat suit would be a nice diversion. They ended up dead. It was hinted later, that the guy in the suit was a contract killer on his way home. He had no papers on him, no mark that could identify him - he didn't speak a single word. They had to let him go because they had no evidence and the thing they had on him was clearly self-defense - there were several witnesses to clear him.
In February 1997 near Warsaw, highway robbers stopped a car. The men in the car turned out to be the coaches of the Russian and Belarussian teams driving home from the world biathlon championship - as in "skiing and shooting". The car was followed by the team bus - as in "fifty Olympic-class marksmen and equipment". Seeing athletes leaving it with rifles, the robbers guessed it's a good time to exit stage right, and quickly.
In 2008, a suspected serial killer and his crew invaded the home of Lloyd Irvin, Muay Thai and Combat Sambo expert and one of the world's top MMA trainers. After waking Irving up where he was asleep on the couch one perpetrator promptly found himself disarmed and they were forced to flee the scene.
Charles Bronson once related a story in which he was vacationing in Italy, and a mugger came up behind him with a knife and said "You give me money". Bronson turned around and said "No, you give me money." The mugger ran upon realizing he'd just tried to mug the star of Death Wish.
One such incident has become fondly-recalled lore in the Society For Creative Anachronism: After a Society event in New York City, a lady who uses the name "Sir Trude Lacklandia" was walking home late at night and assaulted by several muggers. When she refused to hand over her cash, one tried to stab her with a six-inch knife - only to have the blade turned by the chainmail she was wearing under her woolen cloak. She then drew her (very real) sword, said "I'll see your six, and raise you thirty-five!" before chasing the muggers off. A bard in the SCA afterwards wrote a humorous song about it, which has become quite popular.
A middle-aged, five-foot-seven Asian man was accosted by two armed, six-footer African-American muggers in late 2011. One mugger was admitted to a hospital with cracked vertebrae and the other had his arm broken in several places. The uninjured Asian man waited for police to arrive while eating takeaway yakisoba on the curb next to the muggers' unconscious bodies. The Asian man was later identified as a fourth-dan Aikidoka.
In the 1920's a group of five men attempted to mug a well-dressed man and his two female companions. When the police arrived the sidewalk was covered in blood, none of it belonging to the intended victim. The victim was Harry Greb usually ranked either first or second on all-time, pound-for-pound boxing lists who, had by this, time acquired a 261-20-17-1 record.
Around 2008 in Canada, two rednecks in a pick-up truck come across a guy and his girlfriend in a fancy car. They heckle him with lots of cursing and insults while driving right behind them and filming the incident on their camera the whole time. The guy in the fancy car is eventually cornered by the two rednecks at a dead-end; when the rednecks get out of their truck with a baseball bat and walk toward the guy, the guy pulls out a handgun and tells them to back off. The guy's girlfriend takes the camera, and the guy takes the rednecks' truck key and tosses it in a nearby sewer before driving off and later uploading the camera footage to YouTube.
In the early 1700s, Dick Turpin, famous highwayman, once stopped a gentleman on a coach road and threatened him with a pistol. That 'gentleman' turned out to be Thomas King, another famous highwayman. King was so impressed that he took Turpin as a partner and they robbed and murdered on the Essex roads together for two years.
In 1999, a thief stole the wallet of who he thought was a tourist in Seville Airport and ran. That "tourist" was Maurice Greene, World Champion sprinter who set the world record for the hundred-meter dash. The thief didn't get very far.
In Lebanon in the 1980s, terrorist groups frequently kidnapped Western diplomats and held them hostage. Not so much with representatives of the USSR. As the (perhaps apocryphal) story goes, there was a reason for that. A terrorist group once kidnapped a Soviet diplomat, then cut off his finger, which was sent to the Soviet embassy in Beirut as proof that they had him. The Soviet response, after a short KGB "investigation," was to send a box to the terrorist leader containing his beloved brother's head. The hostage was swiftly released, and Soviet diplomats were never bothered again.
The same thing occurred with a group of terrorists who took a Lebanese airliner hostage. After the plane was retaken with no casualties, the Lebanese authorities sat the terrorists in the first row of the first class seats, put towels around their necks, and slit their throats. Never attack a group of people perfectly willing to go much farther than you.
Also the burglar who broke into the house of an olympic fencer... while she was training.
In 2009, a burglar broke into the house that four undergrad medical students were living in late at night. They had already had a Playstation and two laptops stolen earlier that week. When one of the students heard the noise downstairs, he investigated, armed with a katana. When he encountered the burglar, the burglar lunged at him. The med student severed the burglars hand and then slashed him down the torso, causing him to die of blood loss at the scene.
In 1971, legendary boxer Jack Dempsey was taking a cab home with his wife, and was accosted by a mugger. Apparently, the mugger never knew what hit him. Dempsey was 78 at the time.
While Bruce Lee was making a film, one of the actors, assuming all of his moves were fake, insisted on fighting him. He quickly found out that Bruce Lee was a real life martial arts master, after being quite painfully beaten.
What's even better is that when he tries to get away, she grabs him by the collar and pulls him back in obviously not finished with him, and when he finally manages to get away she continues to chase him.
In 2007 a terrorist attack on Glasgow Airport using an incendiary device failed to take into account the presence of Glaswegians. A nearby cab driver intervened, resulting in a magnificent newspaper headline in the Daily Record: "I kicked burning terrorist so hard in balls I tore a tendon in my foot."
In 2010, a group of forty train robbers stormed a train in West Bengal and started taking valuables from the passengers. One of the robbers then decided to rape one of the women on the train. It turned out that one of the train's passengers was Bishnu Shrestha, a corporal in the 8th Gurkha Infantry. And Bishnu objected, sternly, resulting in him killing several of the robbers by himself with just his kukri and sending the rest fleeing for their lives.