Unbound-to-bound transition of two-atom polaritons in an optical cavity