Leigham Richards carried out the offence at the property in Hyde Park as he was suffering a "psychotic episode."
Leeds Crown Court heard the offence took place at Victoria Court Mews on February 1 this year.
Adam Keenaghan, prosecuting, said Richards forced entry to the accomodation at 6pm and two students were alerted by the noise.
Most Popular
-
1
Leeds thunderstorms warning as Met Office shares latest weather forecast
-
2
Bloody machete attack on busy Leeds street left man scarred for life
-
3
York Road incident: Police appeal after pedestrian killed in crash outside Leeds Dogs Trust
-
4
Leeds Bradford Airport: Full statement on August security staff strike
-
5
Jesus Moreno: Friends looking for missing Piglove Brewing Co founder issue map of key search routes
The 29-year-old was holding a metal bar and was wearing a balaclava, dark clothing and had his face covered by a bandana.
He confronted the students and shouted threats as he waved the weapon.
Mr Keenaghan said Richards began asking the students why they had been watching him and forced them to go downstairs with him.
The prosecutor said: "He said this was his city and accused them of stealing his wi-fi and conspiring to break into his home."
Richards then left and police were contacted.
Officers found Richards in a nearby car park.
He refused to drop the metal bar and swore at officers before throwing the weapon against a wall.
The occupants of the student accommodation later noticed that damage had been caused to the doors of some of the flats.
Richards was interviewed and claimed he was being harassed by the students.
He said his e-mails had been hacked and that they had been "controlling his TV".
The defendant said he had taken the metal bar from an old bed in his home.
Richards, of Victoria Road, Hyde Park, pleaded guilty to affray and possessing an offensive weapon.
The victims provided statements to the court describing how they were left shocked and distressed by the incident.
One said: "I didn't have a clue what he was capable of."
Nicholas Hammond, prosecuting, said Richards had been the victim of a stabbing in Leeds city centre in February last year and it had affected his mental health.
Mr Hammond said Richards had been diagnosed as going through a psychotic episode at the time of the offending.
The barrister added: "It is clear that this was completely out of character.
"It is right to say that he has gone through a traumatic incident which resulted in serious injury to himself.
"Shortly after, the country went into lockdown. He lives alone and his mental health deteriorated."
Richards was given an eight-month prison sentence, suspended for 12 months.
He was also ordered to complete 15 rehabilitation activity requirement days and pay £340 court costs.
Judge Simon Phillips QC said: "You acted in a very hostile and aggressive way."