The series does not present a detailed mechanism of how magic works in its universe (why would it?), but the understanding presented in the show is this:
In the resurrection ritual for Tommy Kinkle, Agatha is killed, and thus the ritual is balanced – at first. A life is given (Tommy’s) and a life is taken (Agatha’s).
Later, Agatha is resurrected by using the Cain Pit, which has the magical power to do this. Here, a life is just given (Agatha’s). However, this does not violate some hard rule as it is never stated that the Cain Pit requires a sacrifice or similar, e.g., it resurrects Hilda without one. (On the other hand, Hilda later alludes to the Cain Pit requiring some sort of balance, but does not elaborate further.)
So, there does not seem to be a universal law of nature that deaths and life must be balanced.
(This would be difficult with a growing population anyway.)
Instead, it’s just that the forces powering the ritual require a balance.
You may compare this to buying something (Tommy’s life) with a bad cheque (Agatha’s life).
And indeed, when reality tries to cash the metaphorical cheque in the next episode, it bounces, and problems ensue.