Police illegally searched suspect for gun, court rules