The Messenger of Allah (ﷺ) was in a cave (or raid) when his finger was hurt.

Sahih Muslim Book 32 Hadith 137

Sahih Muslim #1796 b

The Book of Jihad and Expeditions 32:137

It has been narrated on the authority of Aswad b. Qais who said:

The Messenger of Allah (ﷺ) was in a cave (or raid) when his finger was hurt.

Chapter: The persecution suffered by the prophet (saws) at the hands of the idolaters and hypocrites

Grade: Sahih