All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger.
The scholars differed in opinion about whether it is permissible or forbidden for a person who passes by a wall [above which fruits extend outside] or a garden [whose fruits extend outside its fence] to eat from its fruit without the consent of its owner.
Imaam An-Nawawi said: "In our opinion [according to Ash-Shaafi'i School] it is not permissible to eat anything from it unless one is in a necessity the same that allows a person to eat the dead meat; this is the view of Imaam Maalik, Abu Haneefah, Daawood and the majority of the scholars, may Allaah have mercy upon all of them."
The evidence for this opinion is the saying of the Prophet : "The wealth of a Muslim person is forbidden except with his consent." [Ad-Daaraqutni]
However, according to one of the two views of Imaam Ahmad it is permissible to eat from a garden which does not have a wall around it or a guard, even without a necessity, and that is whether the fruits are on the trees or have fallen down on the ground.
The Prophet said: "If anyone of you passes by a wall surrounding a garden and he wants to eat from its fruits, then he has to call the owner three times, if there is no answer, then he can eat from it. And if anyone of you passes by a herd of camels, and he wants to drink its milk, then he has to call "O owner of the camels" or "O shepherd"; if there is no answer, then he can drink from its milk." Besides, Ibn 'Umar narrated that the Prophet said: "If anyone of you passes by a wall surrounding a garden and he wants to eat from its fruits, he can do so but he should not take anything with him."
Furthermore, in one of the opinions of Imaam Ahmad he considers that the permissibility is restricted to the necessity.
Nonetheless, there is no doubt that the opinion of the majority of the scholars is better in order to be on the safe side. However, if one eats after calling the owner of the garden three times, it is expected that there is no harm on him.
Nonetheless, it should be noted that the permissibility in this case is where there is no wall or fence that surrounds it, but if it has a wall or fence, then he should not eat from it.
Ibn 'Abbaas said: "If there is a wall around the garden, then this is a protection. So one should not eat from it, and if the garden has no wall surrounding it, then there is no harm in eating from it."
Allaah Knows best