Answered by Shaykh Yusuf Weltch
How do we reconcile between the prohibition of worshiping at graves vs the recommendation of going to graves?
In the Name of Allah, the Most Merciful and Compassionate
The prohibition of the Prophet (may Allah bless him and give him peace) in the narration from Bukhari which you quoted applies to worshiping Prophets.
Worshiping anyone other than Allah Most High is prohibited and the greatest of sins, shirk (associating partners with Allah Most High). This prohibition is not specific to Prophets; any worship of other than Allah Most High is prohibited regardless of who that worship is directed to.
Visiting Graves and Tawassul
Neither visiting the graves, nor supplicating Allah Most High by means of those in the graves is worship of other than Allah Most High.
Visiting the Muslim graveyard is an act of worship, however, it is worship of Allah Most High. One who believes in Allah Most High, does not worship other than Him.
Asking Allah Most High by means of His love for the Prophets and the righteous is not worship of the prophets or righteous. For this reason, the scholars since the time of the Companions till present day have permitted asking of Allah Most High by the rank of the Prophets and righteous. Even more than this, the Messenger of Allah (may Allah bless him and give him peace), himself, taught some of his companions how to make tawassul to Allah Most High through him.
See this article about Tawassul by Shaykh Nuh Ha Mim Keller for more details on this issue.
Hope this helps
Allah knows best
[Shaykh] Yusuf Weltch
Checked and Approved by Shaykh Faraz Rabbani
Shaykh Yusuf Weltch is a teacher of Arabic, Islamic law, and spirituality. After accepting Islam in 2008, he completed four years at the Darul Uloom seminary in New York, where he studied Arabic and the traditional sciences. He then traveled to Tarim, Yemen, where he stayed for three years studying in Dar Al-Mustafa under some of the greatest scholars of our time, including Habib Umar Bin Hafiz, Habib Kadhim al-Saqqaf, and Shaykh Umar al-Khatib. In Tarim, Shaykh Yusuf completed the memorization of the Qur’an and studied beliefs, legal methodology, hadith methodology, Qur’anic exegesis, Islamic history, and several texts on spirituality. He joined the SeekersGuidance faculty in the summer of 2019.