Farmland is barred, and gift does not help
The rule sits in the FEMA property regulations. An NRI or OCI may buy immovable property in India, but the permission is expressly for property other than agricultural land, a farmhouse or a plantation. So a flat, a house or commercial space is allowed, and farmland, a farmhouse or a plantation is not, whatever the funding.
The common workaround, taking the land as a gift from a resident relative, does not work here either. The gift permission is also written for property other than agricultural land, a farmhouse or a plantation, so those three cannot be gifted to an NRI any more than they can be bought. That leaves one lawful route to hold farmland as an NRI, and it is not a purchase.
Inheritance is the only lawful route
An NRI or OCI can acquire agricultural land, a farmhouse or a plantation by inheritance. You may inherit such property from a person resident in India, or from a person resident outside India who had themselves acquired it in line with the foreign-exchange law in force at the time.
So the farmland your parents owned in India can pass to you as an NRI on their death, and you can hold it. What you cannot do is add to it by buying more, or take a neighbour's plot as a gift. This is why so many NRIs end up owning ancestral farmland but hit a wall trying to buy any, the law lets it come to you by succession, not by purchase.
If you already bought, and selling inherited land
If you have already bought farmland as an NRI, it is a contravention of FEMA, but it can usually be regularised. The breach is penalised under Section 13, and it can be voluntarily compounded, settled by paying a penalty, through the RBI under Section 15, rather than left hanging. Note that compounding cures the exchange-control breach only; it does not fix a title problem under a State's land-ceiling or tenancy laws, and several States separately bar non-farmers from holding agricultural land, a second hurdle beyond FEMA.
When it comes to selling, whether inherited or otherwise held, agricultural land, a farmhouse or a plantation can be transferred by an NRI only to a person resident in India. You cannot sell it to another NRI, an OCI or a foreign buyer. A practising CA, with a FEMA lawyer where needed, handles the compounding application and structures a sale to a resident correctly.