Why do we use resistors(R1 and R2) in transistor NOT gate?
Generally the resistors are required. Take R2. If you replace it with an open circuit, then no current from the input signal can get to the transistor base, so of course it cannot work. If you replace it with a short and apply a voltage such as 5V, a great deal of current will flow and the transistor will be destroyed.
In the special circumstance that the input signal effectively has some series resistance you might not need R2. For example this 'OR' gate:



simulate this circuit &ndash; Schematic created using CircuitLab
We can increase R5 to 10K or 11K and eliminate R2, if we don't care about the voltage swing of the node /(A+B), which will now swing from &lt; 100mV to about 600 or 700mV.
Similarly if R1 is replaced by a short, the output is connected directly to +5V and the voltage cannot change (and the transistor will quite likely destroy itself trying to pull it low). If it is open then when the transistor is off the voltage will remain at 0V. In the case of a specific kind of load that has current flowing out of it, you might be able to eliminate R1. For example:



simulate this circuit
If we don't care about the voltage swing at the node /A we can eliminate R1  (leave it open). The voltage will only swing from about 0V to some intermediate voltage depending on the leakage of the LED and transistor.