Rivals heal your Pokemon, because they're obliged to. Don't get me wrong, but as protagonist (and a real person), it is destiny and skill, that makes you and your Pokemon stronger than everybody else in the game. Plus, more often than not, the rivals themselves need your help with certain parts of the game, such as crossing a difficult terrain, et cetera. So, to pay you back, rivals heal you up.
Another thing that strikes me is that the above mentioned case doesn't deal with exactly rivals, per se. As for the obvious main rival, (s)he doesn't generally heal your Pokemon, unless it is before a major boss battle (and you need your full strength) and he/she stupidly decides to fight with you, as opposed to the baddie (cuz screw logic), and therefore must make amends.
Anyway, the other answers given by Luke777 and DEOXYS123 are right as well, and it is done by GameFreak to help the player and reduce the difficulty (keep in mind tht a lot of young children play the game too)