Doesn't the second sentence convey the idea of something that should have been done but hasn't?
Yes, it does convey that idea...if the teacher knows that something that should have been done, hasn't been done. There are two variations of 'should' and 'ought to' when using *reported speech.
HAVE TO and MUST can express necessity.
HAD TO is the past form of 'must' and 'have to' when they express necessity.
"You have to work harder, John," said the teacher.
"You must work harder, John," said the teacher.
The teacher told John that he had to work harder.
OUGHT TO and SHOULD can express advisability.
*
"You ought to work harder, John," said the teacher.
1)The teacher told John that he ought to work harder.
----In this case the teacher does not know if John followed the advice to work harder.
2)The teacher told John that he ought to have worked harder.
----In this case the teacher knows that John did not follow the advice.
"You should work harder, John," said the teacher.
1) The teacher told John that he should work harder
---In this case the teacher does not know if John followed the advice.
2) The teacher told John that he should have worked harder.
---In this case the teacher knows that John did not follow the advice
thanks to learner for the clarification!