Was the teacher right to do this?
Yes and no. One might be tempted to say that giving a student administrative rights is highly problematic, and leaving them unattended even more so. And to some degree, I even agree with it. You may have added a new administrative user, changed the admin credentials, installed a rootkit or more.
Acting maliciously would not have been without consequence to you. It's very likely that the teacher recalls giving you specifically administrative rights, and at what time. If in this very specific time window, something were to happen to that computer, the school can easily identify you as the malicious actor.
What consequences could there be? That depends entirely on what you did. Changing the local admin credentials could be considered a mere prank, and could probably be reversed by the domain admin. The damage would not be too high, but you could face detention.
If you were, for instance, to install a rootkit, then the school could claim you acted maliciously, with an intent to circumvent their security and to damage their systems. Arguing against that, when you installed what is essentially malware on their system, is going to be very difficult. It could be considered willful damaging of school property, and you could be expelled from school.
If you were to act even more destructive, by running malware designed to damage the hardware (e.g. hypothetically by overclocking the CPU to 12 GHz and disabling any self-preserving safety measures), then the school may even sue you for damages, in addition to expelling you.
Doesn't this imply that the teacher is at fault for providing me admin rights?
No. The teacher gave you administrative authorization to perform a very specific task. That does not give you the right to perform any task, even if you technically had the capability to do so.
If my friend were to give me the key to his house to watch over his dog, this does not authorize me to take anything from his house, or to install cameras everywhere - even if I was technically capable of doing so.
Can this not be considered a penetration test?
"I was just testing the security of my school's computer systems."
No, it's not a penetration test. A penetration test requires the entity, who owns the system, to explicitly consent to the penetration test. A teacher providing you with administrative access to fulfill a specific task is not explicit consent for a penetration test.
What could the teacher have done differently?
Depending on the length of the task you were supposed to carry out, the teacher could have stayed with you and revoked your administrative access after you were done.
Given what was stated above, the teacher had a reasonable expectation that you would not act maliciously, which seems to have been misplaced.