I don't know if there's a foam with this property, but anisotropically conductive tape is readily available: It basically consists of regular tape with a lot of embedded metal "blobs"-> The metal makes contact in the Z direction while not shorting out the pins next to it. It's sold by 3M as Z-Axis electrically conductive double sided tape, but it's expensive af.