The audio is captured by the outward facing microphones used for active noise cancellations. That’s why it only works for AirPods Pro 2, 3 and AirPods 4 with ANC. That wouldn’t just work with any headphones.
Even the AirPods Pro 2 will need a firmware update. They won’t work with just any old headphones and seeing that even the AirPods Pro 2 need a firmware update tells me that it is something they are doing with their H2 chip in their headphones in concert with the iPhone.