It is not entirely clear why German students knock on their tables at the end of a lecture. But there are some explanations where this custom might come from.
This site mentions that the knocking was originally (in the 18th century) done with sticks, which were used by students to attend lectures. This was done to welcome the Füchse (new students) or to show the disagreement with a point a professor made. Over time this knocking with sticks was exchanged for stomping with feet and ultimately with knocking on the table. Also the intent of this custom changed. It became a gesture of appreciation for the lecturer.
Another site basically states the same. But it also takes into account that students were able to continue taking notes while knocking (like @knut already mentioned in the comments). Additionally it states that knocking is not only done at the end of a lecture, but might also occur in between to show that the audience agrees with a statement the lecturer made.
Here you can also find basically the same information as in the second page mentioned. Additionally it mentions the custom of knocking your fist on the table if you disagree with something the lecturer said.
So in conclusion one can say that it is not entirely clear where the custom of knocking on the table with your knuckles originated and when or why it changed its meaning from a negative to a positive one.