Why is legality not always equal to justice in the context of lawmaking?

The Chief Justice of India said legality alone does not make a law just. I wish to examine situations where laws may be legal but not necessarily just, and what principles should guide lawmakers.