By law refers to the condition set by the legislation.
In this case, it relates to the last day of the month, as the last day of the month is the particular date set by the law; however there is no special connection (outside of this contract) between the term by law and the last day of the month.
It could just as easily read: by law the contract will terminate on the first day of the year.
Does this answer your question or have I misread your problem?
I am not a teacher.
Student or Learner