What is wrong with this sentence and why? I would like to have a grammatical explanation. 我们八点上课，老师八点半才到了。
了 indicates the verb is 'completed'
我们八点上课，老师八点半才到。 would be a correct sentence
才 in 八点半才 indicated 'reaching 8:30' is a requirement for the action 'arrive' to apply, therefore, 到 is not a definitely completed action here. That is why the verb particle 了 that indicates the verb is 'completed' is not applicable when it is following 才 in a sentence.
我们八点上课，老师七点半 就到了 would also be a correct sentence, because 就 indicates 'already' therefore the verb particle 了 that indicates the verb is 'completed' is applicable
才 functions differently in different context
八点半(才) = (only when it is) 8:30 ; 八点半(才)到 = arrive (only when it is) 8:30
(才) 八点半 = it is (just) 8:30; (才)八点半就到 = It is (just) 8:30, he already arrived; (才)八点半就到(了) = It is (just) 8:30, he (had) arrived already
In Example 1. 'when it is 8:30' is a requirement for 'arrive' to happen. Therefore, you cannot add '了' to indicate the verb is completed
Verbs taking 才 do not take 了。(https://resources.allsetlearning.com/chinese/grammar/Expressing_lateness_with_%22cai%22)