In case of forfeiture under contract of purchase, the purchaser, and in case of foreclosure of deeds in trust or mortgages, the mortgagor shall be entitled to cultivate and gather the crops, if any, planted by him and grown or growing on the premises at the time of the commencement of the suit; and shall, after eviction therefrom have the right to enter thereon for the purpose of completing the cultivation and removing the crops, first paying or tendering to the party entitled to the possession a reasonable compensation for the use of the land. The court may, on demand of the defendant, adjudge the sum to be paid or tendered.