Those who obeyed the Law knew that sexual intercourse with anyone other than their partner was not allowed. No extramarital affairs. No fooling around. Zero promiscuity. Zero tolerance, but what they didn't know (until Jesus told them) that even thinking about it was just as bad as doing it.
Turns out adultery doesn't start in our beds, but in our heads, our minds, our hearts, and our most intimate internal thoughts that only God knows and sees. Jesus reminded them, and reminds us, it's not enough to follow the letter of the Law. We have to follow the Spirit of the Law. It's not just external. It happens from the inside out.