Why do we need to use transistors when building an OR gate?

What you describe is called a wired OR connection. It is possible in some logic families, particularly ECL (emitter coupled logic), but not in the most common ones (TTL and CMOS).

In CMOS it isn't possible because when a CMOS output is low, it creates a very near short from the output pin through the chip to ground. And when it is high, it creates a very near short from VDD through the chip to the the output pin.

So if you tied two CMOS outputs together and one output high while the other output low, you'd have a very near short from VDD to ground, which would draw a large current and likely overheat one or the other of the two chips involved.

For TTL, there's a similar issue, but the "shorts" from the output pin to VDD or ground aren't quite as near short as they are in CMOS.

There's a variant output style, called open drain for CMOS or open collector for TTL, that allows wired AND connections rather than wired OR. These outputs are designed to only be able to sink current to ground, not to be able to produce any output current when they're nominally in the high state. These are normally used with an external pull-up resistor so that the output voltage will actually reach the "high" voltage level when required.

Note: Open collector or open drain can be used for wired OR if you use active-low logic (low voltage represents logic 1, high voltage represents logic 0).


this lets you "join the outputs"

schematic

simulate this circuit – Schematic created using CircuitLab


If you just connect the wires, you'd have the (fairly likely) possibility of a 0 and a 1 together. Since a 0 is gnd, and a 1 is 5V (depending on the chips, but it's a standard), you'd have 5V and gnd connected together by wires. The term for that is a short circuit!

You could use diodes for a simple OR gate. Or even resistors. The problems occur when you connect this gate to other gates, other circuitry. You can build an AND gate from 2 diodes the other way round. But if you try connect a lot of them together you end up with one giant circuit that doesn't function as small separate parts, but as one big one. Connections that aren't in your simple gate plan, might crop up in real life, messing up what you want to happen.

A transistor lets you separate the input from the output. The output of a transistor can't feed backward and affect it's input. A relay would be another alternative, though slower. Since the switch can't affect the electromagnet.

Early logic was RTL or DTL, resistor-transistor logic, or diode-transistor logic. Resistors, at first, then later diodes, were used to form the gate, then a transistor acted to buffer the result so the next gate you used didn't feed back through this one to it's inputs.

Now, since transistors on chips are virtually free of charge, financially that is, we have the luxury of everything being properly buffered and separate. Usually that's what we want. TTL logic!