First: visiting graves in order to supplicate for the deceased, asking Allah to grant them forgiveness and mercy, and to take heed from the condition of the dead and what they have come to, thereby receiving a lesson and reminder. This is the prescribed form of visitation.
Second: visiting them in order to supplicate there for oneself and one’s loved ones, believing that supplication in graveyards or at the graves of the righteous is better and more likely to be accepted and answered. This is a reprehensible innovation.
Third: visiting them in order to supplicate to Allah while seeking to draw near to Him through the status or rights of the deceased, saying, “My Lord, I ask You by the status of so-and-so,” or, “by the right of so-and-so.” This is a prohibited innovation and a means leading to polytheism.
Fourth: visiting them in order to invoke those buried there, appeal to them for aid, and ask them for succor, assistance, healing, and other things. This is major polytheism that takes a person outside the fold of Islam.
We ask Allah to preserve us and you and to grant us success in every good. He is indeed All-Hearing and Responsive.