I am sorry for your daughter. That is not how a 9 year old (or for that matter any student) should be treated. And the words she used are unprofessional. You can email that teacher and ask her exactly what she meant to convey by the words that were spoken during the incident while letting her know that you are trying to understand the situation better. CC the principal or admin on the email.
The teacher's response was that she was "ashamed" of DD for completing it so quickly
As for why she might have said that - when a coach/teacher sends thought provoking problems in the assignments, they expect the student to take a long time on each problem, mulling over different strategies and learn by the thinking process as well as by solving the problems - this is what my son's chess coach tells him when he solves difficult strategy puzzles in under 5 minutes - so, I think that math teacher thought that the assignments were very challenging for the class and that it would take a long time to complete - it was obvious that it was not hard or challenging for your daughter - the teacher may be reaching the limits of the enrichment or acceleration that she can provide for your daughter - and hence lashed out at her and took away the books. I consider it immaturity on the teacher's part, panic that she does not know how to handle bright students and ignorance because of preconceived notions that many teachers have about "algebra readiness".
Do contact her and bring up the issue - the teacher has to be called out for this kind of behavior. Good luck.