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:82

And as for the wall, it belonged to two orphan boys in the city, and there was beneath it a treasure for them, and their father had been righteous. So your Lord intended that they reach maturity and extract their treasure, as a mercy from your Lord. And I did it not of my own accord. That is the interpretation of that about which you could not have patience."  

And as for the wall, it belonged to two orphan boys ˹who lived˺ in the city, and beneath it there was a treasure, a buried trove of gold and silver, belonging to them. Their father had been a righteous man, and so because of his righteousness they were protected both in ˹terms of˺ their souls and their possessions, and your Lord desired that they should come of age, that is, ˹He desired for them˺ the attainment of maturity, and extract their treasure as a mercy from your Lord (rahmatan min rabbik is a direct object denoting reason, operated by ˹the verb˺ arāda, ‘He desired’). And I did not do it, namely, what has been mentioned of ˹his˺ making a hole in the ship, the slaying of the boy and the repair of the wall, of my own accord, that is, ˹out of˺ my own choosing; nay, it was because of a command in the form of an inspiration from God. This is the interpretation of that over which you could not maintain patience’ (one may say istā‘a or istatā‘a to mean ‘he had the capacity for ˹something˺’; in this instance and the previous one both forms ˹of the verb˺ have been used. Moreover, there is a variety of expression in the use of fa-aradtu, ‘I desired’, fa-aradnā, ‘We desired’, and fa-arāda rabbuk, ‘Your Lord desired’).
القرآن:١٨:٨٢

وَأَمَّا الْجِدَارُ فَكَانَ لِغُلَامَيْنِ يَتِيمَيْنِ فِي الْمَدِينَةِ وَكَانَ تَحْتَهُ كَنْزٌ لَهُمَا وَكَانَ أَبُوهُمَا صَالِحًا فَأَرَادَ رَبُّكَ أَنْ يَبْلُغَا أَشُدَّهُمَا وَيَسْتَخْرِجَا كَنْزَهُمَا رَحْمَةً مِنْ رَبِّكَ ۚ وَمَا فَعَلْتُهُ عَنْ أَمْرِي ۚ ذَٰلِكَ تَأْوِيلُ مَا لَمْ تَسْطِعْ عَلَيْهِ صَبْرًا  

{وأما الجدار فكان لغلامين يتيمين في المدينة وكان تحته كنز} مال مدفون من ذهب وفضة {لهما وكان أبوهما صالحا} فحفظا بصلاحه في أنفسهما ومالهما {فأراد ربك أن يبلغا أشدهما} أي إيناس رشدهما {ويستخرجا كنزهما رحمة من ربك} مفعول له عامله أراد {وما فعلته} أي ما ذكر من خرق السفينة وقتل الغلام وإقامة الجدار {عن أمري} أي اختباري بل بأمر إلهام من الله {ذلك تأويل ما لم تسطع عليه صبرا} يقال اسطاع واستطاع بمعنى أطاق، ففي هذا وما قبله جمع بين اللغتين ونوعت العبارة في: فأردت، فأردنا فأراد ربك.