The Messenger of Allah ﷺ said, "Whatever town you come to and settle in, your share is in it. And whatever town disobeys Allah and His Messenger, a fifth of it belongs to Allah and His Messenger, and the rest is yours."
وقال رسول الله ﷺ أيما قرية أتيتموها فأقمتم فيها فسهمكم فيها وأيما قرية عصت الله ورسوله فإن خمسها لله ورسوله ثم هي لكم
This is a sahih hadith, narrated by Muslim in his Sahih, vol. 4, p. 361, Shab edition. He said, Ahmad bin Hanbal and Muhammad bin Rafi narrated to us, they said, Abdul-Razzaq narrated to us, Mamar informed us from Hammam bin Munabbih who said, this is what Abu Hurairah narrated to us from the Messenger of Allah ﷺ. He then mentioned several hadiths, among them this one, saying, the Messenger of Allah ﷺ said, "Whatever town you come to and settle in, your share is in it, and whatever town disobeys Allah and His Messenger, a fifth of it belongs to Allah and His Messenger, then the rest is yours."The judge said, it is possible that what is meant by the first case is the fay that the Muslims did not obtain by advancing with horses and mounts, but rather its people left it or made a settlement over it, in which case their share in it means their due from the grants, just as fay is distributed. What is meant by the second case is what was taken by force, which would then be spoils of war, from which a fifth is taken out, and the rest belongs to those who took it, and that is the meaning of his saying "then it is yours," meaning the rest of it.Some who do not hold that a fifth is due on fay have used this hadith as evidence. Shafii held that a fifth is due on fay, just as everyone held that it is due on spoils of war, while all the other scholars said there is no fifth due on fay.Ibn Munzir said, we do not know of anyone before Shafii who held that a fifth is due on fay, and Allah knows best. End of quote. [Sahih Muslim with the commentary of Nawawi. It was also narrated by Abu Dawud in the chapter on land tax, from Ahmad bin Hanbal.]