If you are climbing or descending at high rates and change the altitude to something close to your present passing level, the system may not capture the selected altitude. I was descending at 2500fpm and suddenly instructed to level off 700ft below the level I was passing, the autopilot failed to capture and I had to disconnect and manually return to the cleared level.
A TCAS RA overrides an instruction from ATC, once you have called "TCAS RA" the controller is no longer responsible for separation. When you report clear of conflict you will usually return to your previously cleared level, however a revised clearance may be issued.