Just for the sake of trivial knowledge (your comment is obviously correct that it varies) it is actually forbidden in Sardinia (Italy) to replace farmland with solar power fields.
You are only allowed to setup photovoltaic panels if you have plants below them (asparagus and some flowers grow fine, apparently).
You could probably install solar panels for the purpose of powering your house and farm equipment, but you couldn't install solar panels everywhere and sell the electricity to the public:
"Utility facilities necessary for public service, including wetland waste treatment systems but not including commercial facilities for the purpose of generating electrical power for public use by sale or transmission towers over 200 feet in height."
It's not just a local thing: Maybe there are places where it doesn't hold, but the government wants to ensure the US isn't dependent on other countries for food. So it puts restrictions on the farmland to ensure that there's always enough food available.
OTOH, if by 'farmland', you meant 'desert in Nevada', I can't imagine anyone would care if you bought it up and installed panels there.