The first Criminal Code of Peru, approved in 1863, included sodomy as a criminal act.
From 1836 to 1838, the Bolivian Penal Code, which was imposed by General Andrés de Santa Cruz when the Peru–Bolivian Confederation was established, did not expressly prohibit homosexuality. In Peru, consensual same-sex sexual activity has been legal since the enactment of the 1924 Penal Code. Following the fall of the Inca Empire in 1572, the Spanish introduced the death penalty for sodomy. Indeed, Francisco de Toledo and other Spaniards were reportedly "horrified" to find that homosexuality and premarital sex were practised by the Incas upon their arrival in the 16th century. This would suggest that homosexuality was practised by Inca nobility. They lived in temples with the women and dressed in garments, and were particularly liked by noblemen. Male prostitutes, on the other hand, seem to have been treated with certain privileges. Despite this, they seem to have been highly valued by unmarried young men. Women were not allowed to talk to them, or otherwise they would be publicly shaved, and married men who had sexual relations with them would be punished by having their hands and feet tied and then being judged by their wife's family. Female prostitutes were regarded with contempt. Male and female prostitution also existed in the Inca Empire. Lesbians (known as holjoshta) enjoyed many privileges and could even participate in combats and were given the possibility of maintaining promiscuous relations between themselves.
Lesbian relationships seem to have been highly regarded by Inca society.
Effeminate men were called hualmishcu or warminchu by the Incas. Quariwarmi were cross-dressing shamans, tasked with performing rituals in honour of Chuqui Chinchay, a jaguar dual-gender god. According to certain sources, homosexuality and cross-dressing were tolerated "acts of worship", commonly practised in religious rituals and temples. Most modern-day documentation about the Incas stems from the Spanish Inquisition, which introduced Christianity to Peru and South America and regarded homosexuality as sinful. The Inca Empire's perception of homosexuality is unclear and is the subject of ongoing debate. The Aymara people regarded homosexuals as supernatural beings and shamans, capable of magic. However, many of these ceramics and artefacts were destroyed by the Spanish who viewed them as immoral. Similarly, the Chimú civilization (900-1470 AD) did not view homosexuality negatively, and Chimú ceramics depicting homosexual activity exist to this day. About 40% of Moche ceramics ( huacos) depict female and male homosexual relations. The Moche civilization (100–700 AD) did not regard homosexuality negatively or bore pejorative attitudes against it. Main articles: LGBT history in Peru and Homosexuality in ancient Peru During the first Lima Pride parade in 2002, most demonstrators wore masks to avoid persecution by the public. Known LGBT persons may face persecution by the public. In the 1980s, the founding of the organisation Movimiento Homosexual de Lima (MHOL) managed to bring about at least a slight change in the way the media treated homosexuality. Society's attitude towards homosexuals has generally been hostile and is still heavily influenced by the Catholic Church. Laws meant to protect "public morals", such as Article 183 of the Penal Code on "obscene exhibitions and publications", have also been used against lesbians and gays. Homosexuality has been used as grounds for separation or divorce. In March 2018, the ruling was reversed by the Supreme Court of Peru on procedural grounds. In a landmark ruling published on 9 January 2017, the 7th Constitutional Court of Lima ruled in favor of recognizing and registering a same-sex marriage, between a Peruvian citizen and a Mexican citizen, performed in Mexico City in 2010. In January 2017, a decree issued by President Pedro Pablo Kuczynski prohibiting all forms of discrimination and hate crimes on the basis of sexual orientation and gender identity took effect. However, households headed by same-sex couples are not eligible for the same legal protections available to opposite-sex couples. Same-sex sexual activity among consenting adults is legal. Lesbian, gay, bisexual, and transgender (LGBT) people in Peru may face legal challenges not experienced by non- LGBT residents. Yes, sexual orientation and gender identity protections Lesbians, gays and bisexuals allowed to serve openly since 2009 Transgender people allowed to change legal gender without surgery