Pokemon often do this a lot when you play with them, feed them pokepuffs or pokebeans and get three hearts or more affection with their trainer (you). Some of the things they do to show their affection are:
- endure hits, leaving them with one hp
- completely avoid opponent's attacks
- cure themselves of status conditions
- land critical hits easier
When you have high affection with your Pokemon, it will trigger special sentences to come up when you are battling. Some of them are (I will use a Rockruff for these examples as a Pokemon and Ally for these examples as a trainer. Wherever it says Rockruff or Ally, you or your Pokemon's name will be there if you see the caption.):
- Rockruff can't wait to begin.
- Rockruff looks a bit excited.
- Rockruff seems a bit excited.
- Rockruff is thinking of Pokebeans (only if you have Sun or Moon)
- Rockruff seems a little bit out of it...
- Rockruff seems a little uneasy...
- Rockruff is reassured by Ally's familiar scent...
- Rockruff is remembering the first time it met Ally...
- Rockruff really wants some time to play with Ally...
- Rockruff seems curious on what is going on around it.
- Rockruff seems to be interested in the other Pokemon's scent...
- Rockruff and Ally are breathing in perfect sync with one another!
- Rockruff is bursting with enthusiasm for battle!
- Rockruff is looking at Ally with trusting eyes!
- Rockruff seems curious about Ally's bag...
- Rockruff trusts Ally to come up with the best strategy!
- Rockruff turned back toward Ally and nodded in understanding!
As you may assume, different captions and affects come at different times and some captions and affects only come when you have reached a certain level of affection with your Pokemon. For example, the last caption only comes when you are in a battle against a gym leader, kahuna, elite four member, or the champion.
NOW FOR THE ANSWER TO THE QUESTION YOU ASKED IN THE FIRST PLACE (why does my Pokemon shake after coming out of the pokeball?):
It is another sign of affection. Pokemon only shake when they have high affection with you.
Here are the sites I used (you may find them useful to you):