“כל הנגע במת בנפש האדם אשר ימות ולא יתחטא את משכן ה’ טמא וגו’ עוד טומאתו בו” (י”ט,י”ג)
The מחבר (סימן ד’ כיף י”ח) writes “אלו דברים צריכין נטילה במים וכו’ אף ההולך בין המתים ומי שנגע במת” – if one was in the cemetery or touched a dead corpse he must wash his hands. Some are of the opinion that one needs to wash his hands only once while others are of the more stringent view that you have to wash them three times. The מהרי”ל writes that one should also wash his hands before entering the cemetery to daven. After leaving the cemetery besides for washing one’s hands there is a מנהג to also wash one’s face. When leaving kivrei tzadikim that are not in a cemetery for example קבר רחל and קבר רשב”י the מנהג is not to wash one’s hands.
The מגן אברהם (הלכות תשעה באב סימן תקנ”ט ס”ק ט”ו) brings from the כתבי האריז”ל that one should only go to the cemetery for לויית המת, especially if he did not fix up the sin of קרי since all sorts of טומאה will attach themselves onto him. Reb Moshe Feinstein zt”l (אגרות משה יו”ד ח”ב סי’ קס”ב) says that according to the אריז”ל one shouldn’t go to the cemetery to visit קברי אבות, however this is not the מנהג and we do visit the cemetery. The מנחת אלעזר explains that the אריז”ל meant one should not go for no reason, to daven there however is permissible. He is fulfilling the mitzvah of כיבוד אב ואם when he visits the kevarim of his parents. The ב”ח (יו”ד סוף סימן רי”ז) writes משתטחין על קברי אבות ומתפללין לפניו ית”ש על כל צרה שלא תבא בזכות אבותיו הנקברים פה, וכבר נתקנו סדרי תפילה להמשתטחים ואין שום מורה למנוע ולבטל מנהג זה” – the מנהג is to daven by קברי אבות and there is no reason to annul this מנהג.
The Gr”a writes in a letter to his family that one should never go to the cemetery, especially women because of the קליפות that attach themselves to the person. “וכל הצרות והעוונות באים מזה” – all the problems and sins are the result of going there. The חיי אדם writes that one should not go within ד’ אמות of the grave especially one who has not purified himself from טומאת קרי.
The פלא יועץ (ערך טהרה) says that one should immerse himself in the mikvah before going to the cemetery in order that the impure spirits should not attach themselves to the person. Even more so, when leaving the cemetery one should immerse in the mikvah to remove the רוח הטומאה from himself.
Reb Itzila Volozhiner once wrote two amulets for two bochurim who were sick. He wrote them on a fast day. First he immersed in the mikvah afterwards he went to the קבר of his father Reb Chaim Volozhiner. He then immersed in the mikvah again, then he wrote the amulets.
Even if one only attended a funeral without going to the cemetery, the רמ”א (יו”ד (סימן שע”ו says the מנהג is to wash one’s hands. One should also not enter a house before washing his hands. We don’t want the רוח הטומאה to come in and be מזיק the people in the home. The מנהג is also not to dry your hands after washing and not to pass the washing cup from one person to the next. The חכמת אדם says that one needs to wash his hands before entering a house only when coming from a funeral. When returning from visiting the cemetery one may wash his hands in the house. The מנהג not to dry one’s hands also applies when returning from the cemetery.
Prepared by R’ Avrohom Yehoshua Ziskind
 Before the Skalya Rebbe left Vein by the Second World War he wanted to daven at the kever of his father. He asked one of his Chassidim to go together with him. This Chassid was very scared and nervous. The Rebbe was dressed in his chassidishe clothing with his long beard and peyos and the Nazis ym”s were already searching for him. He knew though that he had to heed the words of his Rebbe. He hired a taxi to take the Rebbe to the cemetery. The Rebbe didn’t change his clothing. The only thing he did was tuck his beard under his clothing, and they then entered the taxi. The Rebbe then turned to his Chassid instructing him to tell the driver to first take them to the mikvah. The Chassid tried telling the Rebbe that they were now in a situation of סכנת מות and it wasn’t the time to go to the mikvah, but the Rebbe wouldn’t hear of it. While the Rebbe ran into the mikvah the Chassid went to buy cigarettes for the driver that he shouldn’t reveal to the Nazis ym”s that the Rabbiner was in his taxi. They then went to the cemetery where the Rebbe entered and davened by himself, then they returned home b’shalom ויהי לנס (Sefer Taharas Yisroel).
 Sources:משנה ברורה, אוצר פלאות התורה,נטעי גבריאל,פסקי תשובות טהרת ישראל,כל בו ליארצייט