In 1970, homosexual acts were still outlawed in parts of the United Kingdom and would remain so for more than a decade. Yet two years before the nation even had its first official Gay Pride rally, the quintessentially British songwriter Ray Davies of the Kinks wrote “Lola,” a song that embraced a full spectrum of gender nonconformity. “Girls will be boys/and boys will be girls,” he sang, before emphasizing “it’s a mixed-up, muddled-up, shook-up world/except for Lola.”

The song shot to No. 2 on the British singles chart, hit the Top 10 in the United States and went all the way to No. 1 in five other countries. The response even took its author by surprise. “I didn’t think the song would be so ahead of its time,” Davies said. “But time has proven it so.”

To emphasize the single’s pivotal role, and to celebrate its 50th anniversary, Davies has assembled a sprawling boxed set that adds remixes and outtakes to the album that contained it, “Lola Versus Powerman and the Moneygoround, Part One.” The LP, a witty and scathing sendup of the music industry’s exploitation of artists, turned around the fortunes of the commercially flagging Kinks, making so deep an impression on a then 12-year-old Wes Anderson that when he grew up to become a director, he used three songs from it for his 2007 film “The Darjeeling Limited.”

“I planned scenes in our movie around ‘This Time Tomorrow’ and ‘Strangers’ specifically,” Anderson wrote in an email. “Sublime songs by a band of brothers, which sort of relates to the movie. Then I made another scene, just in order to do a trilogy out of it” with “Powerman,” he added.

In a video call from his home studio in the Highgate area of North London, Davies spoke with his usual wry candor. He has been living there since the pandemic began — though “living is a loose term,” Davies said. “It’s more like being in prison.”

But he acknowledged that lockdown has given him time to assemble the boxed set and begin writing a new play based on the Powerman characters, a work that could serve as a half-century-removed “Part Two” to the original.

The creation of “Lola Versus Powerman” came at an especially fraught time in Kinks history. They hadn’t had a major hit in four years, a situation exacerbated by the band being banned from touring America. Davies cites their refusal to sign papers to satisfy the unions as one reason. Another had to do with an incident on the TV show “Hullabaloo.”

After the camera cut away to a few other guests, it arrived on the Kinks, revealing the drummer Mick Avory and Davies dancing cheek-to-cheek. “Everything we could do to annoy people, we did at the time,” Davies said with a laugh. “Nowadays that would be acceptable. Not then.”

Despite the consequence to the band’s career, “the highest accolade is to be banned from America,” he added.

The band’s break from touring the U.S. gave Davies the chance to soar creatively, leading to his first concept albums, “The Kinks Are the Village Green Preservation Society” and “Arthur (Or the Decline and Fall of the British Empire).” But with “Lola” he aimed squarely at the charts. For a fresh sound, Davies sought an instrument that would stand out on the radio. He found it in a National resonator guitar, a brand of dobro that has the hard, tinny sound of a banjo. “My dad was a banjo player,” Davies said. “He said, ‘If you want a hit record, you have to get a banjo on it.’ The National guitar was the next best thing.”

Next, he searched for an irresistible chorus hook, then road-tested it at home. “I had a 1-year-old child at the time,” Davies said. “She was crawling around singing ‘la la, la la Lola.’ I thought, ‘If she can join in and sing, Kinks fans can do it.’”

As for the song’s bold subject matter, many stories have been told over the years about its inspiration. Davies said it came from an encounter at a nightspot in Paris the group frequented called the Castille Club: “One of our crew at the time met this beautiful blonde and he took her back to the hotel. In the morning, he saw the stubble growing on her chin. So, he got a surprise!”

Davies said his empathy for Lola stems from growing up with six older sisters. “We used to dress up and have parties at home,” he said. “Men dressed as women. My dad, who is the most macho man you could imagine, used to put on a wig occasionally and dance around and make a fool of himself, which I encouraged. It’s part of the musical hall culture we have over here. It’s more accepted in London.”

Davies’ portrayal of Lola, he said, reflects his general approach to character. “When I write songs, I put myself in the part,” he explained. “In ‘Sunny Afternoon’ I wanted to know who this broken-down aristocrat was, and I became him. In Lola’s journey, I did a bit of research with drag queens.” He added, “I admire anyone who can get up and be what they want to be.”

He believes the lyrics to the song “passed” among less open listeners because “people only hear a third of the lyrics when they’re playing a song before they make up their mind they like it. They’ll just listen to the catchy parts.”

The subject matter also sailed over the heads of the BBC censors, who only balked at the lyrical mention of Coca-Cola, which violated its rule about commercial insertions. In reaction, Davies subbed in “cherry cola” on an alternate version.

While gay references had cropped up in pop songs before, “‘Lola’ was the first big hit with an L.G.B.T. theme,” said JD Doyle, a music historian who ran the authoritative radio show “Queer Music Heritage.” “‘Lola’ made history.”

According to Davies, “Lola” encouraged other songwriters to explore related territory. “Before he passed away, Lou Reed told me that ‘Lola’ was a big influence on him,” he said. “It was reassuring to him when he did ‘Walk on the Wild Side.’

Later in the ’70s, Davies wrote “Out of the Wardrobe,” about a straight man who likes to cross dress, which first upsets his wife before she comes to enjoy it. Likewise, the narrator in the Kinks’ “On the Outside” encourages the lead character to accept their identity, which Davies now describes as transgender. “It’s somebody going through a tremendous emotional trauma about having to be somebody they know they’re not,” he said.

Lola was one of the few likable characters on “Powerman.” Much of the rest of the album — which also features two striking songs penned by Davies’ brother, Dave — was inspired by an onerous record deal that made it difficult for the Kinks to earn money. “It’s an old story of artists getting signed to impossible contracts,” Davies said. “I took it personally.”

Ironically, the success of the single and album propelled the Kinks to a new contract and a fresh future. But one song they recorded for the album, “Anytime,” was left off because Davies felt it was “too commercial for its own good.” (The song has a sound and sentiment similar to the Beatles’ “Hey Jude.”)

The boxed set features a new version of the track, expanded by a fresh monologue delivered by a mysterious female character addressing a world of isolation and loneliness that reflects life during the pandemic. It’s a subject that has hit Davies particularly hard since one of his older sisters died of the coronavirus earlier this year. “We weren’t able to go to the funeral,” he said.

For the boxed set, he conducted a series of interviews with his brother, Dave, with a broader purpose in mind: to spark a reunion of the Kinks, who haven’t been together for 23 years. “I’d like to work with Dave again — if he’ll work with me,” Davies said. “Hopefully this will inspire him to trust me more.”

For now, there’s the new play he’s creating that pushes the “Lola Versus Powerman” story forward. “The continuity of my work, and the Kinks’ work, is very important to me,” Davies said. “I write everything with the big picture in mind.”