It is narrated from Abu Sa'id Khudri (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) said: I used to forbid you from visiting graves, but now you may visit them, and do not say anything wrong.
Hadith Referenceمسند الإمام الشافعي / كتاب الجنائز / 605
Hadith Takhrijاخرجه مسلم، الجنائز، باب استئذان النبي صلی اللہ علیہ وسلم ربه في زيارة قبر امه (977) والنسائی، الجنائز، باب زيارة القبور (2035) عن بريدة۔