Gunman who killed three police officers and wounded two others in Canada is in custody after more than a day on the run, police say.