are teachers allowed to penalize grades on an assignment for a student's behavior that was unrelated to the assignment?

for context, it didn't happen to me, but kids in my class had 10% deducted from their test grade whenever they talked during testing time. i read somewhere that teachers weren't allowed to meddle with grades most of the time, i just wanted to make sure