Investigation launched into blunder with HMCTS urgently working with the police to return defendant to custody