Robert Durst appears in a criminal courtroom for his trial on charges of trespassing on property owned by his estranged family. (Mike Segar/Reuters)

Convicted felon Tyler Smith appeared on National Geographic Channel’s “Doomsday Preppers,” brazenly shooting a gun. Kody Brown and his four wives starred on TLC’s “Sister Wives” knowing that polygamy was illegal. Real estate heir Robert Durst agreed to participate in hours of interviews for HBO’s documentary series “The Jinx: The Life and Deaths of Robert Durst” — even though he knew the filmmakers were digging into his connection to three murders.

Thanks to damaging evidence revealed in the season finale, Durst was arrested and charged with murder. The entire media spectacle brought up many questions, among the most puzzling: Why do people go in front of the camera when they know the exposure could ruin them?

[Timing of Robert Durst’s arrest: Coincidence or something more?]

It’s rarely a good idea. During the finale of “The Jinx” on Sunday, Durst’s attorney, Chip Lewis, appeared frustrated as he recalled advising his client that there were serious risks in participating in the documentary.

“You run the risk of pissing people off — and people that have intentions contrary to your liberty,” he said he told Durst. “Don’t forget that.”

Lawyerspeak translation: You could end up in handcuffs. Warnings didn’t matter: Durst wanted to tell his story. Of course, Durst was integral to his own downfall: He was caught on a live mike muttering, “What the hell did I do? Killed them all, of course.” That, perceived by many as a confession, doesn’t look good. But even if he hadn’t made that slip, how could Durst agree to be the subject of a documentary anyway, given his past?

Psychology experts say many times, it boils down to one thing: the chance to become a star conquers all other thinking, even legal consequences. This happens repeatedly in reality TV, where people see fame and dollar signs and tend to forget — or disregard — that there could be serious repercussions for their outrageous behavior.

[Did an HBO show solve a 14-year-old murder case?]

“Ironically, the consequences of ‘reality’ TV don’t seem real to the people who risk being caught at something,” said Los Angeles psychiatrist Carole Lieberman. “It’s as though they believe the TV world doesn’t intersect with the real-world consequences. They are too caught up in thinking that once they become celebrities, these minor nuisances won’t matter.”

Take Tyler Smith, a convicted felon living outside Tacoma, Wash., featured in NatGeo’s “Doomsday Preppers” survivalist series in 2014. Smith took his gun out for target practice and boasted that if a disaster happened, he would loot his neighbors’ belongings. Shortly after the episode aired, police caught wind of it, and Smith was arrested for illegally possessing a firearm.

“What led us to this guy was himself,” Pierce County Sheriff’s office detective Ed Troyer told the local news. “He put himself on TV.”

Fast forward a year later, and Pierce County Sheriff Paul Pastor has an explanation: There are people who break the law and then “don’t behave in a very smart manner.”

“As you might imagine, people were going, ‘What the hell was he thinking?’ ” Pastor told The Washington Post. “But there are times when not every person who breaks the law is a criminal mastermind.”

Experts also say that wannabe stars, many of whom also happen to be narcissists, have feelings of invincibility — which quickly can be proved erroneous. Kody Brown and his four wives found that out in 2010 when TLC debuted their hyped reality series “Sister Wives,” even though their home state of Utah had anti-polygamy laws.

“We know there are risks,” one of his wives insisted to journalists at the Television Critics Association press tour. “For the sake of our entire family, it was an important story to tell.”

The fallout came fast. Just days after the premiere, police launched a bigamy investigation. Even though the family countered that Brown was legally married to only one of the wives, the state considered bigamy to include cohabitation. Brown and his family ended up suing the state — and won the case — but still had to flee to Nevada. In a later interview on Oprah Winfrey’s “Where Are They Now?,” Brown said, “We did not know how aggressive the district attorney would be.”

“Admittedly, [the investigation] was brought on by the publicity surrounding the show,” Utah detective Darren Paul said at the time. “It’s rare because most of the time people don’t bring this kind of attention onto themselves.”

So why does anyone do this to themselves? Other experts believe that the urge to participate could reflect a deep-seated longing to get caught. Or perhaps they think they can outsmart police and viewers. Digging deeper, psychoanalyst Mark Smaller believes this could have to do with “vertical splitting,” a human tendency to deny certain consequences of behavior. In other words, there’s such a strong wish to be in the spotlight that it “splits off” from the part of our thinking that acknowledges the high probability of being caught.

He compares it to the way many of us justify getting in our cars to drive on dangerous wintry roads: The convenience of driving outweighs the possibility that we’ll get hurt. “We all have this capacity,” said Smaller, president of the American Psychoanalytic Association.”There can be an extreme version of that. . . where understanding of consequences gets completely put aside.”

But St. Louis bar owner Sam Coffey, who starred in 2013’s “Salvage City”, thinks it’s simply a pragmatic weighing of cost and benefits. The Discovery Channel reality special followed Coffey and his crew breaking into abandoned historic buildings to preserve “historic treasures doomed for the landfill,” according to the network. After it aired, the St. Louis mayor’s office received angry calls about the blatant breaking and entering, and the police investigated.

Eventually, the production company’s lawyer proved that they had received permission to film inside the vacant buildings. (That’s how many shows about illegal activity skirt the law: When Discovery aired “Moonshiners,” about illegal booze brewers, Virginia’s Department of Alcoholic Beverage Control clarified they weren’t investigating because the distillation scenes were just “dramatizations.”)

But Coffey declared that it didn’t matter either way. “I’m going to keep doing what I’m doing,” he told local reporters, “until I’m locked up or a building collapses on me.”

Today, Coffey maintains that wasn’t just a pithy quote for TV; the risk truly was worth it for him. “The reason I agreed to the show is because it gave me an opportunity to talk about something I really believed in, and have a much larger audience to do that,” Coffey said. “For me, it was worth the risk of whatever trouble I would get in.”

But would he recommend it for others? “If they just want to get on TV, that’s one thing,” Coffey said. “But if they have a greater mission beyond themselves they’re hoping to accomplish, then perhaps it’s worth it.”

Is it ever worth it, though? What about Durst? Lieberman, the psychiatrist, theorizes that Durst wasn’t content sitting on the sidelines watching Ryan Gosling play a character based on him in a movie — the 2010 drama “All Good Things,” directed by Andrew Jarecki, who went on to create “The Jinx.” And that, the psychiatrist says, was Durst’s fatal mistake.

“It is Robert Durst’s narcissism that has become his undoing. He offered himself up to be the subject of ‘The Jinx,’ ” Lieberman said. “After there had been a drama about his life with actors portraying him, he wanted to get in on the action himself.”

Read more:

The Jinx’ director says he gave authorities ‘killed them all’ audio months ago

Why faux Robert Durst film, “All Good Things” starring Ryan Gosling, wasn’t very good

‘The Jinx’ finale recap: What led to Robert Durst saying he ‘killed them all, of course’?

‘The Jinx’ finally gets real