I am using Comparator (schematic shown below). I have connected output with Vcc via 2k ohm resistor, as it has open collector output.
In this configuration output of the opamp should be 3.3V. But the output is coming 0V.
But if I change the supply voltage to 5V, then the output is showing 5V. (schematic below)
Is there any rule "voltage at the terminal (inverting/non-inverting) of the comparator should not be higher than supply voltage of the opamp.
It's a comparator, not an op-amp. The question does not arise with op-amps because they generally do not have open drain outputs.
The answer is maybe. You will have to read the datasheet for the particular comparator (assuming it has open drain/open collector output).
In the case of the LM339 the maximum output voltage is 36V regardless of Vcc.
Some comparators may have protection diodes on the output, so the datasheet would likely state a maximum such as Vcc+0.3V.