Sure, you can change the mode of the pin on the fly.
Maybe you start with side set as Tx and the other as RX. At some point the TX side says “send me something in 5mS”. Then the Tx side runs pinMode and changes its output to an input and starts listening. At the same time, the Rx side runs pinMode and sets its input to an output, waits for the 5mS to elapse, then sends the something. Then it runs pinMode back to input and goes back to listening. The original Tx side receives the something goes back to Tx mode, maybe tells the Rx that something was received correctly, maybe not, whatever your protocol calls for.