Where the story is told and the background
Quran 3:123 names Badr, reminding the believers that Allah had given them victory there while they were in a weak position. The passage in Surah al-Anfal, verses 5 to 19, tells much of the story.
Ka'b ibn Malik (may Allah be pleased with him) reported in Sahih al-Bukhari (3951) that the Prophet ﷺ went out intending to meet a caravan of the Quraysh, until Allah brought the Muslims and their enemy together without an appointment. No one who stayed behind was blamed for it.
Quran 8:5-7 describes the mood. A group of the believers were unwilling to go, as if driven toward death. Allah had promised them one of the two groups, and they wished it to be the unarmed one, the caravan. But Allah intended to establish the truth by His words and to cut off the roots of the disbelievers.