One who places his eruv in a cemetery—meaning, upon a built grave which is forbidden for benefit, as is written in Yoreh Deah siman 364—it is not an eruv. For even though at the time of the acquisition of the eruv we are not concerned, as mitzvot were not given for benefit, nevertheless, since it is pleasing to him that the eruv remain thereafter, as it is a matter of food or drink, he thus benefits from it. And even though we need not be concerned with what happens after the acquisition of the eruv, nevertheless, since his intention is to acquire a residence there and it is like his home, and it is forbidden to acquire a home from items forbidden for benefit (Gemara Eruvin 31a)—consequently, this residence is void, and the eruv is void. This is according to the opinion of the Rambam in chapter 6 and our teacher, the Beit Yosef, in section 1. However, the Tur actually ruled that only for a kohen is it not an eruv, because he cannot reach the place of his residence, but for a Yisrael it is. (And that which is in the Gemara is not according to the conclusion, see there).
But if he placed the eruv in a beit hapras—which is a field in which a grave was plowed and its impurity is rabbinic—even for a kohen it is an eruv, because he can enter there in a "flying tower," that is, a tower that holds forty seah and is carried upon animals, or by means of blowing, according to the law of a beit hapras where one blows and sees that there is no bone the size of a barley grain and proceeds. The kohen can also reach the eruv and take it by means of flat wooden vessels which do not contract impurity. So too, a grave in the ground is not forbidden for benefit, as is written in Yoreh Deah there; and according to those who forbid there the earth placed upon the grave, it is not an eruv. These laws are not in their place here to be explained.
הנותן עירובו בבית הקברות, כלומר על הקבר של בנין שהוא אסור בהנאה, כמ"ש ביורה דעה סימן שס"ד - אינו עירוב, דאף על גב דבשעת קניית העירוב לית לן בה, דמצות לאו ליהנות ניתנו, מכל מקום כיון דניחא ליה שיתקיים העירוב גם אחר כך, שהרי הוא דבר מאכל או משקה - הרי נהנה בו. ואף על גב דאין לנו לחוש מה שיהיה אחר קניית העירוב, מכל מקום כיון שכונתו לקנות שביתה שם והוה כביתו, ואסור לקנות בית באיסורי הנאה (גמרא עירובין ל"א.) - וממילא דבטלה שביתה זו, ובטל העירוב. וזהו לפי דעת הרמב"ם בפרק ו' ורבינו הב"י בסעיף א'. אבל הטור באמת פסק דרק לכהן לא הוי עירוב, לפי שאין יכול להגיע למקום שביתתו, ולא לישראל. (וזה שבגמרא אינו לפי המסקנא ע"ש)אבל הניח העירוב בבית הפרס, שהוא שדה שנחרש בה קבר וטומאתו מדרבנן - אפילו לכהן הוה עירוב, מפני שיכול להכנס שם במגדל הפורח, היינו מגדל שיש בו מ' סאה ונישא על גבי בהמות, או על ידי ניפוח כדין בית הפרס שמנפח ורואה שאין שם עצם כשעורה והולך לו, ויכול גם הכהן להגיע להעירוב וליטלו על ידי פשוטי כלי עץ שאינו מקבל טומאה. וכן קבר של קרקע - אינו אסור בהנאה כמ"ש ביורה דעה שם, ולהאוסרים שם בהקרקע שנתנו על הקבר - אינו עירוב, ודינים אלו אין מקומן כאן לבארן.