"Then, when they took him away and agreed to put him into the depths of the well," meaning: they reached an agreement and cast him into it.
﴿فَلَمَّا ذَهَبُوا بِهِ وَأَجْمَعُوا أَنْ يَجْعَلُوهُ فِي غيابات الْجب﴾ أَيْ: اتَّفَقُوا وَأَلْقَوْهُ