This is a good question, as it touches many aspects of our day jobs as programmers. What's important here, is that both teams work for the same organization. Unless your workplace is corrupt, you're all "on the same ship", and you should keep afloat as an organization and not as individual teams. From that perspective, the request to continue assisting team A ensures that they will not drown.
To get back to your personal concerns: it's hard to remain focused, but it's harder if you don't know what you're expected to do, and what you'll be judged by. If you feel peoples' expectations (yours, team A's, your managers') cannot be met, you can, and perhaps should, bring this up with the people responsible for that. Regardless of their job titles, they're usually the folks in charge of finances and scheduling. It's imperative NOT to complain, but to bring this up as a question, and to assume everybody is trying to do their best. Maybe team A needs more assistance than the schedulers predicted, and team A decided to ask for this themselves without including a 'planning' person. While this style of direct communication between teams is fine in many organizations, the responsibility to notify the 'planners' of potential delays lies with the teams.
Once the 'planning' folks are aware of the high demand of both teams, they can decide what is best on a larger scale of things; depending on which client pays more, deadlines, and the responsibilities they think team members should take on, they can make a decision that benefits the organization most. If all goes well, you should have a much clearer idea of what your employer would like you to do, and it'll be much less stressful to meet these expectations. Do keep in mind that, even if you no longer like the code team A has to work with, it's reasonable for your employer to ask you to remain involved for a while longer. If it helps, you can consider this a personal challenge in mentoring/training, rather than developing your technical skills.