This situation should not actually arise if you are handling your faculty job search properly. If you accept an offer, you should withdraw all your remaining job applications. Otherwise either you are wasting their time in considering you for a position you won't accept, or you were insincere in accepting the previous offer. If you aren't comfortable withdrawing your other applications, then you aren't comfortable accepting the job. You can negotiate on this point, for example by telling them that another job would solve your two-body problem and you hope they can wait on a final decision until you hear about that job, but there's no guarantee that they will agree.
The basic ethical principle here is honesty: you shouldn't give someone a decision they understand to be final without actually meaning it. By default, job acceptances are considered binding decisions in the parts of academia I'm familiar with (certainly in mathematics in the U.S.), so you can't just assume that of course they knew you might change your mind. If you have any reservations or conditions, you should make them explicit before accepting the position. This can't hurt you if nobody really considered the decision to be final in the first place, and it will avoid unethical behavior if they did.
Even though this shouldn't happen, people do occasionally get themselves into this situation. If you unilaterally rescind your initial acceptance and take the other position instead, you face almost no legal risk, since nobody's going to try suing over this. However, you can hurt your reputation, which is a serious danger.
Instead, the way you should handle it is by careful discussions. Typically, University 2 will let you defer their offer for at least a year, since otherwise they look like jerks for trying to steal you away from University 1 after you already accepted an offer. (Another possibility is that University 2 had no idea you had already accepted and will rescind their offer upon learning this.) Then you approach University 1 and apologize profusely for inadvertently creating a terribly awkward situation. You explain that you are willing to come to University 1 and fulfill your obligations, but you have an offer from University 2 and you would very likely leave after a year to go there, so you wonder whether there is any chance they would release you from your acceptance. If they agree, then you are ethically free to accept University 2's offer immediately. (University 1 still won't be happy with you, so you shouldn't do this unless it really matters to you, but asking them for permission is much better than just announcing you aren't coming.) If University 1 insists that they need you next year, then you defer University 2's offer and show up at University 1.
But you really shouldn't let yourself get further faculty offers after you've already accepted a job. You might be able to get away with it once by explaining that you accidentally forgot to withdraw your other applications, but you really don't want to develop a reputation over time as someone who deliberately manipulates the system in unethical ways.