How did Legalism come about?

Can you answer this question?