Clean the connector (I use alcohol wipes, gently) and let it dry, then retest. Try it turned both ways, too.
Are your headphones a direct lightning connector or are you using a lightning to 3.5 jack dongle?
I’ve got the dongle + 3.5 jack wired EarPods because I switch to an old laptop w a jack often. (I just leave the dongle on the phone to switch back if it rings.)
Sometimes I’ve had EarPods fail but the dongle was still good & sometimes the reverse. I seem to have ‘something’ die about every 9 months or so even with gentle handling. Test each part with another you know is good.