Tamid 28b: Rabbi Eliezer ben Yaakov says: From where do we derive the law that we may not build a wooden portico in the courtyard of the Beis Hamikdash? Because the Torah says, “Do not plant an asheirah, any wood next to the mizbeyach of Hashem your G-d” (Devarim 16:21).
Sifri, Shoftim: From where do we derive the law that we may not plant a tree or build a house on the Temple Mount? Because the Torah says, “Any wood next to the mizbeyach of Hashem your G-d.” Rabbi Eliezer [ben Yaakov] says: From where do we derive the law that we may not build a wooden portico in the courtyard of the Beis Hamikdash? Because the Torah says, “Next to the mizbeyach of Hashem your G-d.”
The Rambam (Avodah Zarah 6:9) rules in accordance with the first opinion in the Sifri that one may not plant a tree, but adopts Rabbi Eliezer ben Yaakov’s condition that it is only forbidden in the courtyard, not the entire Temple Mount.
Rabbi Akiva Eiger Orach Chaim 150:1: Planting a tree next to a shul is Rabbinically forbidden.
תמיד כח ע”ב: תניא ר’ אליעזר בן יעקב אומר מנין שאין עושין אכסדראות בעזרה ת”ל לא תטע לך אשרה כל עץ אצל מזבח ה׳ אלהיך, הכי קאמר: לא תטע לך אשרה, לא תטע לך כל עץ אצל מזבח ה׳ א-להיךִ.
ספרי שופטים: ומנין לנוטע אילן ובונה בית בהר הבית שהוא עובר בלא תעשה ת״ל כל עץ אצל מזבח ה׳ אלהיך. ר׳ אליעזר אומר מנין שאין עושים אכסדרה בעזרה ת״ל אצל מזבח ה׳ א-להיך.
רמב”ם הלכות עבודה זרה ו,ט: הנוטע אילן אצל המזבח או בכל העזרה, בין אילן סרק ובין אילן מאכל, אע”פ שעשאו לנוי למקדש ויופי לו – הרי זה לוקה, שנאמר: “לא תטע לך אשרה כל עץ אצל מזבח ה’ אלקיך”, מפני שהיה זה דרך העכו”ם נוטעין אילנות בצד מזבח שלהם כדי שיתקבצו שם העם.
ר’ עקיבא איגר או”ח קנ,א: וכתב ר’ דוד עראמה בפירוש להרמב”ם, דאפילו אצל בית הכנסת אסור מדרבנן.
Once, someone decided to plant trees in the courtyard of the main shul of Bnei Brak. The Chazon Ish, basing himself on Rabbi Akiva Eiger, was against the idea. But he did not wish to impose his view on others, so he came up with a clever trick: he sent people to each of the major rabbis in Bnei Brak, telling each one that Rabbi So-and-so had permitted the planting of the trees. This, he reasoned, would motivate them to forbid it, since it is human nature for a rabbi to want to show everyone that he has a mind of his own and does not just go along with what everyone else says. Thus all the rabbis would forbid it.
In the end, however, the trick failed and all the rabbis permitted planting the trees.
Source: Divrei Siach, Vayechi 5781