The President of the High Court has demanded a "very full" explanation from the HSE about why a psychiatrically ill man with a long history of paedophilia was allowed to leave hospital and move freely in the community at least four months after reports warned he was a danger to children.

A report in November 2017, warned that the man represented a sexual risk to children but Mr Justice Peter Kelly said the situation may have been going on before that.

He said he was very concerned that the HSE appeared to have been aware since at least November of the danger the man posed to children, but nothing was done.

He said it was "purely providential" that no child had suffered at the man's hands.

He asked what the point was of having tribunals and commissions of inquiry into things that happened years ago, if things like this were still happening today. 

Mr Justice Kelly said the man may not have criminal culpability because of his mental capacity, but that would be of small comfort to any victim.

The court heard the man is in his thirties and from a very chaotic and troubled family background. 

He has schizo affective disorder and a mild intellectual disability but the judge said the alarming thing was that he was involved for some years from 1997, in serious sexual assaults.

He was cautioned in 1997 for committing a serious sexual assault against a girl with special needs who was, like him, in foster care at the time.

Between 1997 and 1999, it was alleged the man claimed to have committed multiple sexual assaults with children between the ages of three and six before he was taken into care.

He was referred to the Grenada Institute which recommended he needed structured living and supervision.

The judge made orders detaining the man in the psychiatric hospital where he has been a voluntary patient since 2014.

The matter had come before the judge in the context of an application to make him a ward of court.

Mr Justice Kelly said the orders mean the man must remain in the hospital, was not permitted any outings and could be arrested by gardaí if he leaves. 

He said these were necessary in the man's best interests and also in the public interest. 

The judge said he wanted a very full and comprehensive explanation with no ifs or buts from the HSE as to how the situation had arisen.

He said he was particularly concerned as he had been told a solicitor met the man last month in relation to the application to make him a ward of court and yet the application was made only this week.