Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:18:77

So they set out, until when they came to the people of a town, they asked its people for food, but they refused to offer them hospitality. And they found therein a wall about to collapse, so al-Khidh r restored it. ˹Moses˺ said, "If you wished, you could have taken for it a payment."  

So they set off, until, when they came to the folk of a ˹certain˺ town, namely, Antioch (Antākya), they asked its folk for food, they asked them for food by way of hospitality, but they refused to extend them any hospitality. They then found in it a wall, one hundred cubits high, about to collapse, that is, it was close to falling down because of its tilt; so he, al-Khidr, straightened it, with his ˹own˺ hands. He, Moses, said, to him, ‘Had you wished, you could have taken (a variant reading ˹for la-ttakhadhta˺ has la-takhidhta) a wage for it’, some ˹sort of˺ payment, since they did not extend us any hospitality despite our need for food.
القرآن:١٨:٧٧

فَانْطَلَقَا حَتَّىٰ إِذَا أَتَيَا أَهْلَ قَرْيَةٍ اسْتَطْعَمَا أَهْلَهَا فَأَبَوْا أَنْ يُضَيِّفُوهُمَا فَوَجَدَا فِيهَا جِدَارًا يُرِيدُ أَنْ يَنْقَضَّ فَأَقَامَهُ ۖ قَالَ لَوْ شِئْتَ لَاتَّخَذْتَ عَلَيْهِ أَجْرًا  

{فانطلقا حتى إذا أتيا أهل قرية} هي أنطاكية {استطعما أهلها} طلبا منهم الطعام بضيافة {فأبوا أن يضيفوهما فوجدا فيها جدارا} ارتفاعه مائة ذراع {يريد أن ينقضَّ} أي يقرب أن يسقط لميلانه {فأقامه} الخضر بيده {قال} له موسى {لو شئت لاتخذت} وفي قراءة لتخذت {عليه أجرا} جُعْلاً حيث لم يضيفونا مع حاجتنا إلى الطعام.