Any opamp can be used as a voltage comparator. Basically feed it two voltages, one on the + input and the other on the - input and the output will tell you which input is higher than the other. This Wikipedia page explains it fairly well, so I won't bore you with my own description.
I will say that your circuit could be doing something slightly different. Most opamps, including the LM741, don't deal well with input voltages that are close to the power rails. Even so-called "rail to rail opamps" have limits on how close an input can get. Your schematics don't show how you connected power to the opamp, so I can't be sure. However, if you connected the negative power pin to GND then this opamp could be operating outside it's normal input voltage range in which case all bets are off as to how it will behave. Even so, it is at least trying to work as a comparator.
Update: I'm adding specific examples of rail-to-rail I/O (RRIO) opamps.
TI OPA170: Advertised as having rail to rail OUTPUTS. The datasheet says that when driving a 1 mA load the "output voltage swing from rail" will be a minimum of 115 mV with no maximum specified (page 3 of the datasheet). Now I might be interpreting the datasheet incorrectly, but I read that as saying they offer no guarantee of RRO's. A couple of lines later they say that over the entire temp range the output voltage won't be better than 0.35v from the rails. This chip doesn't claim to have rail to rail inputs, which is good because the input can't get closer than 2.0v to the V+ rail.
TI LM7321: Advertised as having RRIO. Page 4 of the datasheet says that the output could, under some conditions, be 450 mV from either rail, and typically about 100 mV. Common Mode Input Voltage Range IS rail to rail over entire temp range.
On Semi LMV981: Advertised as having RRIO. Page 3 of the datasheet shows that the output isn't guaranteed to get closer than 170 mV from the rail. Also, it specifies that the Input Common-Mode Voltage Range is rail to rail for limited temperature ranges.
Bottom Line: Your mileage (kilometerage?) may vary. Read the datasheets carefully and don't rely on the bullet list of features on the first page.