What you’re talking about here is an op-amp configured in open loop mode – no feedback resistor, so the output swings + or -, generally in opposition to the higher value on the inputs. When the input voltage is equal – as it would be when you tie both inputs to the same voltage source, you still get one or the other because of the non-ideal characteristics of the op-amp’s internal circuit paths. You don’t use an op-amp as a means of determining whether two voltages are equal. That is best determined with a bridge circuit, in which a galvanometer is placed between the two voltage sources. When it reads 0, the voltages are equal, subject to the accuracy of the meter. However, you can never have two voltages that are completely equal, because of thermal variations, quantum effect, and other non-ideal aspects of a circuit.