It was narrated that Ubay Bin Ka’b [radiyallaahu-anhu] said, “There was a man – and I do not know of any man who lived further away from the Masjid than him – but he never missed a prayer. So it was said to him” or “I said to him, ‘Why do you not buy a donkey to ride when it is dark or when the sand is too hot?’ He said, ‘I would not like my house to be next to the Masjid. I want my walking to the Masjid and my returning when I return to my family to be recorded for me.’ So, the Messenger of Allaah [sallal laahu alayhi wasallam] said, ‘Indeed, Allaah has gathered all that [reward] for him.'”
Shaikh Abdul Muhsin Al-Abbaad [hafidhahullaah] said: Just as this reward is [earned when] going to the Masjid, it is also [earned when] returning home.