"5 for 2 coins" is a woefully underspecified bargain - it doesn't say what you're getting 5 of, nor does it state what the value of the 2 coins is.
The farmer needs to simply sell 5 of something that does not amount to a whole cow. The farmer bought "5 heads for 2 coins", but may instead sell "5 hooves for 2 coins", selling only 1.25 cattle for the same price he bought 5 cattle. The farmer buys 250 cattle for 100 coins, but may recoup his investment by selling only 63 cows. Maybe the farmer markets them as emotional support cows and sells therapy sessions as "5 minutes for 2 coins" until he breaks even, and then takes all 250 cows home as profit.
Alternatively, the farmer may sell 5 heads of cattle for 2 coins of greater value than he bought them for. Maybe he bought the cows for half-dollar coins and sells them for dollar coins. Maybe he is a numismatist and only sells cows for coins with collectible value exceeding their nominal value.
Another solution respecting the size of the cows hint, the farmer simply sells the smallest cows and goes home with the largest ones. He is paying some average price-per-pound when buying the 250 cows, and by selling the smallest cows, for the same fixed price, he is getting a higher price-per-pound. Although the price is set per-cow, it isn't actually true that all cows have the same value. The farmer may buy 500,000lbs of cow for 100 coins, sell more than half the herd for more than half the price on a per-cow basis, yet still have more than half of the total weight remaining. If these cows are bred for meat, that extra weight is profit.