It was a Hollywood requirement. Immoral/criminal behavior could not be promoted as a positive outcome or a film wouldn't be allowed release or something to that effect.
I guess the Graduate had a different ending planned but it wasn't allowed because Mrs Robinson did something immoral (I've never seen the movie or read the book).