In one of the obligatory prayers, the Companions of the Messenger of Allah (sal Allahu alaihi wa sallam) took their places behind the Messenger of Allah (sal Allahu alaihi wa sallam) and offered their prayers. Just as they completed the prayers, a man entered the Masjid. Thereupon the Messenger of Allah (sal Allahu alaihi wa sallam) turned to his Companions and said, “Which one of you wishes to give charity to this brother of yours, thereby receive rewards?”
On hearing these words of blessing from the Messenger of Allah (sal Allahu alaihi wa sallam) one of the Companions stood up immediately and offered the prayer with that man. [Tirmidhi, Salaat]
By praying with that man, the Companion allowed him to get more reward for his prayer (by making it a congregational prayer) than if he were left to pray by himself.
It is not permissible to lag behind intentionally so as to miss the payer in congregation (Jamaat). However, if one accidentally misses it and reaches after the prayer is over, then another Muslim may offer it with him to increase the reward for him and thereby reward himself as well.
Whenever we do a good deed for someone, it is actually a trade, since we will be rewarded for it in return by Allah (subhana wa ta’ala).
Keep your eyes on Allah’s reward and not what the person can do for you in return.