Luke Mallaband, 23, was caught after a woman at the University of East Anglia (UEA)'s library in Norwich realised she was being recorded and reported it.
Mallaband admitted six voyeurism offences at an earlier hearing.
He was given the three-year ban and a six-month curfew at Norwich Magistrates' Court.
Mallaband, formerly of Norwich but now of Yew Tree Road, Walsall, was found to be at "high risk of posing serious harm to females", a probation report found.
Prosecuting, Louise Mantell-Sayer told the court a woman noticed a plastic bag in the gender-neutral toilet cubicle in UEA's library.
The bag had a hole in it which lined up with a hole in a box inside containing an iPhone set to record video.
The woman said she felt "disgusted" and "violated" by what happened.
In defence, Dave Foulkes said Mallaband had no previous convictions and had referred himself to a mental health team in the Midlands.
Police found 38 voyeurism videos on his phone filmed between July 2013 and February this year.
He will also carry out a three-year community order, a 200-hour sex offending behaviour programme and was told to pay Â£170 in costs at Norwich Magistrates' Court.

Angus Laughland, who did not know the girl, exchanged text messages with her after getting hold of her number by chance through a third party.
Perth Sheriff Court heard that Laughland's messages to the girl became sexually explicit.
The 62-year-old was jailed for 220 days after admitting the offence.
The court was told that one of the first texts received by the girl read: "I'm not a person as such, just call me cyber buddy."
Shortly after Laughland started sending the messages, he guessed the girl was around "13 or 14" and she confirmed that she was.
The court was told the messages became sexually explicit, with one making reference to the girl's private parts.
On 11 October Laughland sent a message saying he taught guitar and that he wanted to meet the girl to give her a guitar as a gift.
The meeting took place the following day.
When the girl got home, her mother asked her about the guitar and they discussed the issue with the girl's grandmother.
The teenager's family then contacted the police,
Laughland admitted sending explicit texts to a 13-year-old girl between 16 September and 12 October 2014.
Solicitor Paul Ralph, defending, said: "It started as a grave error of judgement.
"It developed so far beyond that, that it's very difficult for us to really describe how he got himself into that situation."
Sheriff Fiona Tait said: "We ought not to lose sight of what this offence was.
"He described sexual intercourse in detail and also met the child. The difficulty he faces is the gravity of the offence.
"He met the child and gave her the guitar. That shows precisely how vulnerable she was."
A former student who secretly filmed women using showers and toilets has been banned from entering female and gender-neutral loos.
[NEXT_CONCEPT]
A Blairgowrie music teacher who groomed a 13-year-old girl and met her after promising to give her a guitar has been jailed.