It's a behavior called phase reversal. It exist on many but not all opamps.
Basically it works like this: If your input signal exceeds the allowed input voltage range some of the internal transistors in the opamp break down. They shouldn't pass current but you're driving them so hard that they turn on.
The output then flips to the other polarity. Depending on the circuit around the opamp this could even lead to a so called latch-up condition where the output stays at the wrong polarity forever.
In general you should never exceed the allowed input range of opamps. If the phase reversal occurs due to an internal transistor breakdown the transistor may take damage and changes it's characteristics. The OpAmp may seem fine afterwards but it is not guaranteed to work within it's specification anymore.
About OpAmps that may latch-up: Never use them for critical control systems. Think about a heater with temperature control. It senses the temperature and controls a heating element. If your OpAmp is one of those latch-up types it is very possible that at extreme temperatures it runs into latch-up, turns on the heater at full power, stays there forever and burns you house down.
The data-sheet of the OpAmp usually states if it has phase-reversal or if it can latch-up. If this is not mentioned in the data-sheet assume that it does.