Doctors allowed Craig Sanders to leave their care because they did not deem him a suicide risk.
But shortly after being allowed home he travelled to Shrewsbury Railway Station, where he made his way onto the tracks.
A two-day inquest is being held into the death of Mr Sanders, of Radbrook Hall Court, Shrewsbury.
Coroner for Shropshire, Telford and Wrekin John Ellery heard that the 44-year-old died on September 4 last year.
He had entered the station and made his way to platform seven. He died at around 5.20pm.
Evidence was given by two psychiatrists who had been involved with Mr Sanders in the days prior to his death.
Dr Malcolm Locke, a consultant psychiatrist who was on duty at the Royal Shrewsbury Hospital on September 1, said Mr Sanders, who had a history of self-harming, had visited the hospital and had been assessed as needing to be detained under the Mental Health Act. He had been discharged from The Redwoods Centre in the town earlier in the day.
Dr Locke said that he thought Mr Sanders was suffering from borderline personality disorder but not from schizophrenia.
He said he was paranoid and agitated, adding: "He said he had received prior help but had stopped his medication."
He added that Mr Sanders kept talking about aliens, although it was unclear whether he was psychotic.
Dr Locke sectioned Mr Sanders and he was detained at the hospital but was released a couple of days later.
He next saw Mr Sanders on September 3 after he had self-harmed, cutting his leg. "Again he was not showing features of a psychotic illness," said Dr Locke.
"I interviewed him and he was quiet and calm.
"He said he had been self-harming for the last five years. He said he did not feel safe at home and I told him that admission to hospital would not be suitable.
"I did not think he was actively wanting to end his life.
"He gave no indication that he had a suicide plan."
The inquest continues.