Praise be to Allah.
Zakaah on grains is due from the one who owned the crop at the time when the grains became ripe.
Ibn Qudaamah (may Allah have mercy on him) said in al-Mughni (2/300):
The time when zakaah becomes due on grains is when the grain becomes ripe, and on fruits it is when they become ripe and sound. If a person disposes of the fruit or grains before they are ripe, then he does not have to pay anything, because he disposed of it before zakaah became due. This is like the one who eats livestock or sells them before one year has passed. End quote.
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) said in ash-Sharh al-Mumti‘ (6/80): When the grain becomes ripe or fruit becomes ripe and sound, zakaah becomes due; before that it is not due. Based on that, if ownership is transferred from one person to another before zakaah becomes due, then it is not due from him (the original owner); rather it is due from the one to whom ownership was transferred, such as if the owner dies before zakaah becomes due or before the grain becomes ripe or the fruit becomes ripe and sound, then no zakaah is due from him, but it is due from his heir. Similarly, if a person sells palm trees on which there is fruit that has not yet been seen to be sound, or he sells land on which there are crops, the grains of which have not yet ripened, then zakaah is due from the purchaser, because it passed from ownership (of the seller) before zakaah became due. End quote.
Based on that, if the sale was done before zakaah became due – which in the case of grains is before they ripen – then zakaah is due from the buyer. But if he sold the grains after they became ripe, then zakaah is due from the seller, because it became his responsibility before the sale.
And Allah knows best.