How is it possible to replace a relay with transistors?
how can you replace a 4 pin Normally Open (SPST) relays with
transistors when polarity of Emitter and Collector pins are unknown?

Well, I wouldn't use BJTs; I'd use MOSFETs and, two back-to-back MOSFETs with a common photovoltaic drive interface is commonly used in &quot;solid state relays&quot; aka SSRs. Here's a typical example: -

And here's a photovoltaic interface chip that can be used with external MOSFETs: -

And, the great thing about this type of circuit is that you have isolation between input and output (just like a relay) and, it can operate on AC and DC.

Are there any specific components out there that can switch a DC
voltage when polarity is unknown?

The above SSR circuits work just fine but you have to be aware of certain things. The switching is faster than a relay but usually only in the realm of 1 ms. This is mainly due to the photovoltaic part and the need to charge up the gate-source capacitors in any MOSFET.
You should also be aware that switching an inductive load can lead to a recoil voltage (aka a back-emf) and quite often you'll need extra protection circuits to prevent the MOSFETs seeing too-high a voltage when they turn off.