The court appeared ready to invalidate laws in some two dozen states that bar therapists from practicing a version of therapy that seeks to change a teenager's sexual orientation or gender identity.