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:12:15

So when they took him ˹out˺ and agreed to put him into the bottom of the well... But We inspired to him, "You will surely inform them ˹someday˺ about this affair of theirs while they do not perceive ˹your identity˺."  

So when they went off with him, and agreed, resolved, to put him into the bottom of the well (the response of lammā, ‘when’, has been omitted, in other words ˹understand it as being˺ fa‘alū dhālika, ‘they did ˹just˺ that’) by taking off his shirt — after having beaten him, humiliated him and desiring to kill him — and lowering him in a bucket ˹into the well˺. When he reached half-way down the well, they flung him ˹from the bucket˺ so that he would ˹fall and˺ die, but he fell into the water and took refuge near a rock. They then called to him and he responded, thinking that they had ˹decided to have˺ mercy on him. They then wanted to smash his head with a rock, but Judah prevented them. And We revealed to him, in the well, through true revelation (wahy haqīqa) — he was 17 years of age or just under — in order to reassure his heart: ‘Truly you shall inform them, after this day, of this affair, ˹this˺ deed, of theirs when they are unaware’, of ˹who˺ you ˹are˺ (wa-hum lā yash‘urūna is a circumstantial qualifier referring to the action of ‘informing’).
القرآن:١٢:١٥

فَلَمَّا ذَهَبُوا بِهِ وَأَجْمَعُوا أَنْ يَجْعَلُوهُ فِي غَيَابَتِ الْجُبِّ ۚ وَأَوْحَيْنَا إِلَيْهِ لَتُنَبِّئَنَّهُمْ بِأَمْرِهِمْ هَٰذَا وَهُمْ لَا يَشْعُرُونَ  

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