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

And ˹mention˺ when your Lord took from the children of Adam - from their loins - their descendants and made them testify of themselves, ˹saying to them˺, "Am I not your Lord?" They said, "Yes, we have testified." ˹This˺ - lest you should say on the day of Resurrection, "Indeed, we were of this unaware."  

And, remember, when your Lord took from the Children of Adam, from their loins (min zuhūrihim, is an inclusive substitution for the preceding ˹clause: min banī Ādama, ‘from the Children of Adam’˺, with the same preposition ˹min, ‘from’˺) their seed, by bringing forth one from the loins of the other, ˹all˺ from the loins of Adam, offspring after offspring, in the way that they multiply, ˹looking˺ like small ants at ˹the valley of˺ Na‘mān on the Day of ‘Arafa ˹because of their multitude˺. God set up proofs of His Lordship for them and endowed them with ˹the faculty of˺ reason, and made them testify against themselves, saying, ‘Am I not your Lord?’ They said, ‘Yea, indeed, You are our Lord, we testify’, to this, and this ˹taking of˺ testimony is, lest they should say (in both instances, read third person ˹yaqūlū, ‘they say’˺ or second person ˹taqūlū, ‘you say’˺) on the Day of Resurrection, ‘Truly, of this, Oneness of God, we were unaware’, not knowing it!
القرآن:٧:١٧٢

وَإِذْ أَخَذَ رَبُّكَ مِنْ بَنِي آدَمَ مِنْ ظُهُورِهِمْ ذُرِّيَّتَهُمْ وَأَشْهَدَهُمْ عَلَىٰ أَنْفُسِهِمْ أَلَسْتُ بِرَبِّكُمْ ۖ قَالُوا بَلَىٰ ۛ شَهِدْنَا ۛ أَنْ تَقُولُوا يَوْمَ الْقِيَامَةِ إِنَّا كُنَّا عَنْ هَٰذَا غَافِلِينَ  

{و} اذكر {إذ} حين {أخذ ربُّك من بني آدم من ظهورهم} بدل اشتمال مما قبله بإعادة الجار {ذرِّيّاتهم} بأن أخرج بعضهم من صلب بعض من صلب آدم نسلا بعد نسل كنحو ما يتوالدون كالذّر بنعمان يوم عرفة ونصب لهم دلائل على ربوبيته وركب فيهم عقلا {وأشْهدهم على أنفسهم} قال {ألست بربكم؟ قالوا بلى} أنت ربنا {شهدنا} بذلك والإشهاد لـ {أن} لا {يقولوا} بالياء والتاء في الموضعين، أي الكفار {يوم القيامة إنا كنَّا عن هذا} التوحيد {غافلين} لا نعرفه.

See similar narrations below:

Collected by Ibn Ḥibbān

ذِكْرُ إِخْرَاجِ اللَّهِ جَلَّ وَعَلَا مِنْ ظَهْرِ آدَمَ ذُرِّيَّتِهِ، وَإِعْلَامِهِ إِيَّاهُ أَنَّهُ خَالِقُهَا لِلْجَنَّةِ وَالنَّارِ

ibnhibban:6166ʿUmar b. Saʿīd b. Sinān And al-Ḥusayn b. Idrīs al-Anṣārī > Aḥmad b. Abū Bakr > Mālik > Zayd b. Abū Unaysah > ʿAbd al-Ḥamīd b. ʿAbd al-Raḥman b. Zayd b. al-Khaṭṭāb > Muslim b. Yasār al-Juhanī > ʿUmar b. al-Khaṭṭāb Suʾil

[Machine] About this verse (And [mention] when your Lord took from the children of Adam - from their loins - their descendants and made them testify of themselves, [saying to them], "Am I not your Lord?" They said, "Yes, we have testified."), the verse means:  

ابن حبّان:٦١٦٦أَخْبَرَنَا عُمَرُ بْنُ سَعِيدِ بْنِ سِنَانٍ وَالْحُسَيْنُ بْنُ إِدْرِيسَ الْأَنْصَارِيُّ قَالَا أَخْبَرَنَا أَحْمَدُ بْنُ أَبِي بَكْرٍ عَنْ مَالِكٍ عَنْ زَيْدِ بْنِ أَبِي أُنَيْسَةَ عَنْ عَبْدِ الْحَمِيدِ بْنِ عَبْدِ الرَّحْمَنِ بْنِ زَيْدِ بْنِ الْخَطَّابِ أَنَّهُ أَخْبَرَهُ عَنْ مُسْلِمِ بْنِ يَسَارٍ الْجُهَنِيِّ أَنَّ عُمَرَ بْنَ الْخَطَّابِ ؓ سُئِلَ

عَنْ هَذِهِ الْآيَةِ (وَإِذْ أَخَذَ رَبُّكَ مِنْ بَنِي آدَمَ مِنْ ظُهُورِهِمْ ذُرِّيَّاتِهِمْ وَأَشْهَدَهُمْ عَلَى أَنْفُسِهِمْ أَلَسْتُ بِرَبِّكُمْ قَالُوا بَلَى) الْآيَةَ