A mentally ill person who believes God is ordering him to commit a crime is insane "if a person is of a faith that God is good and infallible," a forensic psychiatrist testified Friday during Andrea Yates' second murder trial.

But Yates, who believed Satan wanted her to drown her five children in the bathtub, knew that her actions were wrong and therefore is not legally insane, Dr. Park Dietz said.

That opinion about Yates also is based on her statements that she knew her thoughts were bad and that killing the children was a sin, said Dietz, who evaluated Yates more than four months after the June 20, 2001, drownings.

Click here to visit FOXNews.com's Crime Center.

Click here to visit FOXNews.com's Law Center.

"She had obsessions about a thing (hurting her children) for years, and at some point concluded that it must be Satan," Dietz said Friday, testifying in the prosecution's rebuttal phase under cross-examination by the defense.

Before being blocked by state District Judge Belinda Hill, defense attorney George Parnham tried to bring up the case of Deanna Laney, who bludgeoned her three sons with rocks, killing two of them. She was found innocent by reason of insanity at her 2004 trial in Tyler, Texas.

Dietz testified for the prosecution in that case that Laney did not know her actions were wrong because she had a delusion that God told her to kill her children to prove her faith.

Dietz also testified Friday that a mentally ill person cannot will away a delusion or control its contents.

Yates, 42, has again pleaded innocent by reason of insanity. She will be sentenced to life in prison if convicted of murder.

Her attorneys say she suffered from severe postpartum psychosis and was in a delusional state when she killed her children, believing she was saving them from hell.

Dietz's testimony in Yates' first trial led an appeals court to overturn her 2002 murder conviction.

He said that an episode of the "Law & Order" television series was about a woman being acquitted by reason of insanity after drowning her children in a tub. After Yates' conviction, those involved in the case discovered no such episode existed.

Hill also has barred attorneys from mentioning anything about that issue.

Dietz maintained Friday, based on his review of her medical records, that he saw no evidence of severely psychotic symptoms until Yates was jailed the day after she drowned 7-year-old Noah, 5-year-old John, 3-year-old Paul, 2-year-old Luke and 6-month-old Mary.

But he acknowledged that while she was hospitalized in 1999 after her two suicide attempts, she improved after being given an anti-psychotic medication.

"There was a psychotic process related to her depression," Dietz said.

In addition to his videotaped interviews with Yates, parts of which were shown to jurors Thursday, Dietz said he reviewed her medical records and criminal case file. He said he also reviewed records from her stay in July 2004 at the University of Texas Medical Branch Hospital in Galveston.

He said Yates was depressed over the recent anniversary of the drownings, and then her husband told her he was filing for divorce, which Rusty Yates did in 2005. Andrea Yates was severely dehydrated and showed psychotic symptoms while hospitalized, Dietz said.