LOS ANGELES — A California appeals court overturned the rape conviction of a man who authorities say pretended to be a sleeping woman's boyfriend before initiating intercourse, ruling that an arcane law from 1872 doesn't protect unmarried women in such cases.

A panel of judges reversed the trial court's conviction of Julio Morales and remanded it for retrial, in a decision posted Wednesday from the Los Angeles-based court.

Morales had been sentenced to three years in state prison. He was accused of entering a woman's bedroom late one night after her boyfriend had gone home and initiating sexual intercourse while she was asleep, after a night of drinking.

The victim said her boyfriend was in the room when she fell asleep, and they'd decided against having sex that night because he didn't have a condom and he had to be somewhere early the next day.

Morales pretended to be her boyfriend in the darkened room, and it wasn't until a ray of light from outside the room flashed across his face that she realized he wasn't her boyfriend, according to prosecutors.

"Has the man committed rape? Because of historical anomalies in the law and the statutory definition of rape, the answer is no, even though, if the woman had been married and the man had impersonated her husband, the answer would be yes," Judge Thomas L. Willhite Jr. wrote in the court's decision.

The appeals court added that prosecutors argued two theories, and it was unclear if the jury convicted Morales because the defendant tricked the victim or because sex with a sleeping person is defined as rape by law.

The court said the case should be retried to ensure the jury's conviction is supported by the latter argument.

The decision also urges the Legislature to examine the law, which was first written in response to cases in England that concluded fraudulent impersonation to have sex wasn't rape because the victim would consent, even if they were being tricked into thinking the perpetrator was their husband.

Willhite noted that the law has been applied inconsistently over the years in California.

In 2010, a similar law in Idaho prevented an unmarried woman from pressing rape charges after being tricked into sex with a stranger by her then-boyfriend.

The judge called what happened "despicable" but said the state's law left the court with no choice. Idaho's law was amended to cover all women in 2011.

Morales' attorney Edward Schulman declined comment when reached by phone Thursday.

Prior to the conviction, Schulman had argued Morales believed the sex was consensual because the victim responded to his kisses and caresses, according to the decision.

Also on HuffPost:

Loading Slideshow...
  • Alabama State Capitol (Montgomery, Ala.)

    Pictured on Tuesday, Feb. 7, 2012. (AP Photo/Dave Martin)

  • Alaska State Capitol (Juneau, Alaska)

    Pictured on Tuesday, Jan. 18, 2011. (AP Photo/Chris Miller)

  • Arizona State Capitol (Phoenix)

    Pictured on Friday, April 23, 2010. (Photo by John Moore/Getty Images)

  • Arkansas State Capitol (Little Rock, Ark.)

    Pictured on Wednesday, Nov. 30, 2011. (AP Photo/Danny Johnston)

  • California State Capitol (Sacramento, Calif.)

    Pictured on Thursday, Jan. 5, 2006. (Photo by David Paul Morris/Getty Images)

  • Colorado State Capitol (Denver)

    Pictured on Thursday, Oct. 26, 2006. (Photo by Doug Pensinger/Getty Images)

  • Connecticut State Capitol (Hartford, Conn.)

    Pictured on Tuesday, Feb. 7, 1999. (AP Photo/Bob Child)

  • Delaware State Capitol (Dover, Del.)

  • Florida State Capitol (Tallahassee, Fla.)

    Pictured on Monday, Jan. 3, 2011. (AP Photo/John Raoux)

  • Georgia State Capitol (Atlanta)

    Pictured on Tuesday, November 13, 2007. (Photo by Jessica McGowan/Getty Images)

  • Hawaii State Capitol (Honolulu)

  • Idaho State Capitol (Boise, Idaho)

    Pictured on Monday, Jan. 14, 2008. (Ned Dishman/NBAE via Getty Images)

  • Illinois State Capitol (Springfield, Ill.)

    Pictured on Tuesday, Sept. 21, 2004. (AP Photo/Seth Perlman)

  • Indiana State Capitol (Indianapolis)

    Pictured on Saturday, Feb. 4, 2012. (Photo by Jeff Gross/Getty Images)

  • Iowa State Capitol (Des Moines, Iowa)

    Pictured on Wednesday, Aug. 10, 2011. (Photo by Chip Somodevilla/Getty Images)

  • Kansas State Capitol (Topeka, Kan.)

    Pictured on Thursday, April 15, 2010. (AP Photo/Orlin Wagner)

  • Kentucky State Capitol (Frankfort, Ky.)

    Pictured on Wednesday, April 12, 2006. (AP Photo/James Crisp)

  • Louisiana State Capitol (Baton Rouge, La.)

    Pictured on Monday, Jan. 14, 2008. (Matthew HINTON/AFP/Getty Images)

  • Maine State Capitol (Augusta, Me.)

    Pictured on Monday, Oct. 17, 2011. (AP Photo/Pat Wellenbach)

  • Maryland State House (Annapolis, Md.)

    (Photo by Patrick Smith/Getty Images)

  • Massachusetts State House (Boston)

    Pictured on Tuesday, Jan. 2, 2007. (Photo by Darren McCollester/Getty Images)

  • Michigan State Capitol (Lansing, Mich.)

    Pictured on Wednesday, April 13, 2011. (Photo by Bill Pugliano/Getty Images)

  • Minnesota State Capitol (St. Paul, Minn.)

    Pictured on Friday, July 1, 2011. (Photo by Hannah Foslien/Getty Images)

  • Mississippi State Capitol (Jackson, Miss.)

    Pictured on Thursday, June 10, 1999. (AP Photo/Rogelio Solis)

  • Missouri State Capitol (Jefferson City, Mo.)

    Pictured on Friday, Oct. 16, 2000. (Photo credit should read ORLIN WAGNER/AFP/Getty Images)

  • Montana State Capitol (Helena, Mont.)

  • Nebraska State Capitol (Lincoln, Neb.)

    Pictured on Wednesday, Nov. 25, 1998. (AP Photo/S.E. McKee)

  • Nevada State Capitol (Carson City, Nev.)

  • New Hampshire State House (Concord, N.H.)

    Pictured on Friday, Dec. 28, 2001. (Todd Warshaw//Pool/Getty Images

  • New Jersey State House (Trenton, N.J.)

    Pictured on Friday, Aug. 13, 2004. (Photo by Chris Hondros/Getty Images)

  • New Mexico State Capitol (Santa Fe, N.M.)

  • New York State Capitol (Albany, N.Y.)

    Pictured on Sunday, March 16, 2008. (Photo by Daniel Barry/Getty Images)

  • North Carolina State Capitol (Raleigh, N.C.)

    Pictured in 1930. (AP Photo)

  • North Dakota State Capitol (Bismarck, N.D.)

    Pictured on Thursday, April 19, 2012. (AP Photo/Dale Wetzel)

  • Ohio Statehouse (Columbus, Ohio)

    Pictured on Tuesday, March 8, 2011. (Photo by Mike Munden/Getty Images)

  • Oklahoma State Capitol (Oklahoma City)

    Pictured on Wednesday, Feb. 29, 2012. (AP Photo/Sue Ogrocki)

  • Oregon State Capitol (Salem, Ore.)

    Pictured on Friday, May 20, 2011. (AP Photo/Rick Bowmer, file)

  • Pennsylvania State Capitol (Harrisburg, Pa.)

    Pictured on Thursday, June 28, 2012. (BRIGITTE DUSSEAU/AFP/GettyImages)

  • Rhode Island State House (Providence, R.I.)

    Pictured on Wednesday, Aug. 1, 1945. (AP Photo)

  • South Carolina State House (Columbia, S.C.)

    Pictured on Monday, Jan. 21, 2008. (Photo by Chris Hondros/Getty Images)

  • South Dakota State Capitol (Pierre, S.D.)

    Pictured on Tuesday, Jan. 10, 2012. (AP Photo/Doug Dreyer)

  • Tennessee State Capitol (Nashville, Tenn.)

    Pictured on Tuesday, Sept. 30, 1941. (AP Photo)

  • Texas State Capitol (Austin, Texas)

    Pictured on Tuesday, Oct. 4, 2011. (MIRA OBERMAN/AFP/Getty Images)

  • Utah State Capitol (Salt Lake City)

    Pictured on Thursday, March 15, 2001. (GEORGE FREY/AFP/Getty Images)

  • Vermont State House (Montpelier, Vt.)

    Pictured on April 9, 1953. (AP Photo/Francis C. Curtin)

  • Virginia State Capitol (Richmond, Va.)

    Pictured on Wednesday, May 2, 2007. (Photo by Chris Jackson/Getty Images)

  • Washington State Capitol (Olympia, Wash.)

    Pictured on Wednesday, Jan. 18, 2012. (AP Photo/Rachel La Corte)

  • West Virginia State Capitol (Charleston, W.V.)

    Pictured on July 2, 2010. (MANDEL NGAN/AFP/Getty Images)

  • Wisconsin State Capitol (Madison, Wis.)

    Pictured on Saturday, Dec. 24, 2011. (KAREN BLEIER/AFP/Getty Images)

  • Wyoming State Capitol (Cheyenne, Wyo.)

    Pictured on Tuesday, March 6, 2001. (Photo by Michael Smith/Newsmakers)