One would imagine that when selling a field, the seller can choose whichever buyer he wants. In fact, the Sages rule that there is one person who gets preference over any other buyer – a neighbor. The Gemara has a concept that it calls dina d’bar mitzra – the rule of the neighbor. According to dina d’bar mitzra, if a person sells his field, the person who owns the neighboring field has first rights to purchase it, and in the event that it was sold to another, he has the right to remove the purchaser from the field (obviously he will have to compensate the purchaser for the money that he put out in his attempt to obtain rights to the field).
This law is based on the passage ki ta’aseh ha-tov ve-ha-yashar (Devarim 12:28) – literally, “you should do what is good and what is straight” when involved in business transactions. Since it makes no difference to the seller who pays him for the field, and it certainly does make a difference to the neighbor who wants to purchase the land (since it is easier to work and guard one large piece of land than two smaller ones that are separate from one another) it would be middat Sedom – a characteristic of the city of Sedom (see Bereishit chapters 18-19) – to refuse to sell it to the individual who needs it more. Still, this rule applies only to the sale of land. If the owner of the land wants to give it as a present to someone, dina d’bar mitzra would not apply, since the owner may derive specific benefit from giving his land to a certain person as a gift.
Although our Gemara appears to suggest that a person can avoid the rule of dina d’bar mitzra by writing a shtar matanah – a document that shows a transaction to be a gift – after the sale is complete, in fact from Rav Hai Gaon onwards, the majority of the poskim rule that if the neighbor is aware of the fact that the field was sold and can show the contract of sale, the fact that a second contract was written attesting to the transfer of the field as a present will not remove the rule of dina d’bar mitzra from being applied.