Some habits prove hard to kick. There are two films named The Nun out this summer: a gorgeous restoration of Jacques Rivette’s banned 1966 film starring Anna Karina, and a new prequel in The Conjuring franchise directed by Corin Hardy, in which demon nun Valak (Bonnie Aarons) from The Conjuring 2 torments the novice Sister Irene (Taissa Farmiga) in a Romanian abbey. Clearly, the convent exerts a special fascination on film-makers, because nuns, whether reluctant, rebellious, devout or possessed, have cropped up in many memorable, often controversial, movies.

Valak’s hellish reappearance is hardly designed to please church elders, but Rivette’s film, too, was initially banned in France, a decision that director Jean-Luc Godard likened to a “Gestapo of the mind”. It was released a couple of years later, after it had won applause at the Cannes film festival. It is based on an 18th-century novel by Denis Diderot and follows the progress of an illegitimate teenager, Suzanne (Karina), forced into a convent against her will. It is an austere, elegant adaptation of its satirical source, with long, gruelling takes, an intrusive experimental soundtrack and a passionate central performance from Karina as the young nun, persecuted by a sadistic mother superior in one convent, and sexually harassed by another in a second.

Facebook Twitter Pinterest The Nun, directed by Corin Hardy. Photograph: Warner Bros/PR

You don’t have to look far to find more controversy attached to convent films, the most famous being Ken Russell’s The Devils (1971), the notorious story of Urbain Grandier, a 17th-century priest who was convicted of witchcraft after the nuns in his care became possessed by the devil. With Oliver Reed as the libidinous Grandier and Vanessa Redgrave as the manic, hunchbacked mother superior, the film plays out in the highest possible key, saturated with blasphemous visions and furtive masturbation.

British censors took exception to the film’s combination of religion and violent sexual imagery and demanded several cuts, especially to scenes of naked nuns pleasuring themselves on a statue of Jesus – the “rape of Christ” sequence. The film has now been almost entirely reconstructed and released on DVD, and has had a far kinder critical reception than on its first release. But it remains a gruelling watch. Jerzy Kawalerowicz’s 1961 Mother Joan of the Angels, a beautiful Polish film shot in a stylised and eerie black and white, is loosely based on the same incident.

Satanic possession features greatly in one of the first and best-known appearances of nuns on film. In Benjamin Christensen’s Häxan (1922), the devil is seen encouraging sisters to spear a communion wafer with a knife or steal a statue of the baby Jesus and cause all kinds of holy havoc. However, a sober postscript in that film reminds us that historical cases of female “hysteria” are more likely to be a mental health issue than the devil’s work. Despite that caveat, you can draw a line from these lurid scenes through to The Devils and even Jesús Franco’s sleazy The Demons (1973). They are the more-or-less acceptable face of the “nunsploitation” subgenre, which throws barbs at organised religion while getting its kicks out of twisted sisters getting kinky in the convent. It was recently boosted by the arrival of a hugely popular film with an unmysterious title: Nude Nuns with Big Guns (2010).

Facebook Twitter Pinterest Joan Carroll and Ingrid Bergman in The Bells of St Mary’s, 1945. Photograph: Allstar/RKO

Don’t lose faith though, as there are many shining examples of virtuous nuns on screen. Try Ingrid Bergman as the devout, scrupulous Sister Mary Benedict in Leo McCarey’s The Bells of St Mary’s (1945), a postwar Christmas favourite designed to warm even atheist hearts. Bing Crosby plays the convent school’s new priest, Father O’Malley, who is determined to shake up the rules, but also to engineer a miracle to save St Mary’s. Maureen Sabine, in her 2013 book, Veiled Desires: Intimate Portrayals of Nuns in Postwar Anglo-American Film, writes that Bergman’s character was considered the ideal screen nun at one point: modern, attractive, secure in her faith and capable of some cheery banter with Crosby. As Sabine says, it was the kind of Hollywood portrayal that encouraged young women to take holy orders.

The star power of Bergman, as with Audrey Hepburn who starred in The Nun’s Story (1959), gave her character an allure, suggesting the radiant positivity of faith. However, that star power could undercut the sense of saintliness. When women who had played romantic roles went on to portray nuns, audiences might have expected a little sexual frisson.

One of the greatest nun films of all time is Michael Powell and Emeric Pressburger’s electric Black Narcissus (1947), set in a remote Himalayan convent, where the sisterhood is rapidly torn apart by jealousy and desire. Kathleen Byron’s exit from the convent to follow her earthly passions is marked by a closeup of her applying a deep red lipstick – movie-star glamour in a tube. Deborah Kerr co-stars in the film as a nun struggling to forget a romance from her youth in Ireland.

Kerr would reappear as a nun in the sizzling two-hander Heaven Knows, Mr Allison – the 1957 film directed by John Huston – which also puts a strain on the vow of chastity. Kerr plays a novice nun, Sister Angela, stranded on a South Pacific island in 1944 with Robert Mitchum’s grizzled marine. It is a brilliant movie and the slowest of slow-burn romances. First, the two come to realise their respective vocations have plenty in common when it comes to discipline and service. Then, as they are forced to spend their nights in a cave hiding from Japanese troops, they grow dangerously close.

From Lilies of the Field (1963) to The Sound of Music (1965), The Singing Nun (1966), and the Hayley Mills comedy The Trouble With Angels (1966), 1960s Hollywood provided more innocent interpretations of cloistered life, where rebellion was nothing more than cheekiness and, crucially, the principles of faith remained intact. That is the landscape Rivette’s film entered. It was also the time that nunsploitation reared its wimpled head, reaching its heretical zenith in the 1970s.

Facebook Twitter Pinterest Deborah Kerr in Black Narcissus, 1947. Photograph: Allstar/Universal Pictures

Later films probed a sensitive question: how could nuns remain true to their vocation in a modern world of temptation and women’s liberation? One startling film from 1985, Agnes of God, directed by Norman Jewison, stars Jane Fonda as a psychiatrist sent to investigate a troubling crime in a convent. A young nun, played by Meg Tilly, has given birth in secret and murdered the baby, but refuses to discuss how she became pregnant. Fonda’s dialogues with Tilly, whose psyche seems to have buried the truth beneath holy visions, and the mother superior,a sharp old bird played by Anne Bancroft, crackle with tension. It offers some clues as to why nuns make such appealing screen characters, too. Most importantly, they offer juicy roles for female actors – most of these films ace the Bechdel test. There is another easy win, too. When we think of nuns, we think of what they have renounced. All a nun has to do is wear red lipstick or swear, or, as Bancroft does here, share a cigarette and a joke about apostles, to give an audience a transgressive thrill.

Facebook Twitter Pinterest Whoopi Goldber as Deloris in 1993’s Sister Act 2. Photograph: Touchstone/Sportsphoto/Allstar

The 1980s were a good decade for nuns’n’thugs comedy, from Kathleen Freeman’s “penguin”, who whacked the fear of God into The Blues Brothers with a wooden ruler in John Landis’s 1980 musical, to lairy costume caper Nuns On the Run in 1990. The early 1990s gave us the first Sister Act film, a hugely enjoyable performance by Whoopi Goldberg as Deloris, a casino singer and former Catholic schoolgirl who hides in a convent after she witnesses a crime, and becomes the unlikely star of the choir – it’s a hip update of The Singing Nun’s pop tactics. Maggie Smith offers perfect support as a purse-lipped mother superior, who is horrified by each development. Goldberg’s wisecracks and the film’s rock’n’roll arrangements of church hymns were so popular that it took hundreds of millions at the box office and spawned a stage adaptation and sequel. Now Disney is apparently planning a remake.

In the mid-1990s, nuns continued to consort with sinners. Susan Sarandon won an Oscar for her portrayal of Sister Helen, a wise and witty nun who befriends a death-row prisoner (Sean Penn) in Dead Man Walking (1995), based on a true story. Isabelle Huppert starred in Hal Hartley’s Amateur (1994) as a virgin ex-nun who makes a living writing pornography until she stumbles across her mission from God, and a vast criminal conspiracy. That one definitely isn’t based on fact. Huppert would also go on to play the lead in a 2013 remake of Rivette’s The Nun.

Facebook Twitter Pinterest Sean Penn and Susan Sarandon in the 1995 film, Dead Man Walking. Photograph: Allstar/Working Title

In the 21st century, real-life scandals have burst into the depiction of convent life, most powerfully with the harrowing The Magdalene Sisters (2002), based on the brutal homes for “fallen” girls run by holy orders in 1960s Ireland. One of the best convent films of recent years was Doubt (2008), set in a convent school in the Bronx, New York, in 1964 – an introspective spiritual successor to The Bells of St Mary’s. The character of Bergman’s Sister Mary Benedict is halved and shared between Amy Adams as Sister James, encapsulating her faith and innocence, and Meryl Streep, who embodies rigid discipline as Sister Aloysius. Father Flynn (Philip Seymour Hoffman) is just as charismatic as Crosby’s O’Malley, but the sisters are soon united in their suspicions about his relationship with one of the principals. It is an emotionally devastating film – a crisis of faith in the nun genre that is unlikely to bring in new recruits.

Little in the world of convent cinema is as bleak as Rivette’s cloisters, though – places that offer no solace or sanctuary for his young heroine. Ultimately, The Nun suggests that society, which oppresses young women and undermines the teachings of religion, is to blame rather than the church – perhaps we are really looking elsewhere when peeking over the nunnery wall.

• Jacques Rivette’s The Nun is released in cinemas on 27 July, and on DVD and Blu-ray on 17 September; Corin Hardy’s The Nun is released on 7 September