When the real estate levied on is of greater value than five thousand dollars ($5,000), and is so situated that it cannot be divided so as to set apart the homestead, the freeholders shall certify the fact, and the officer may proceed to sell the whole tract, and out of the proceeds the officer shall pay to the clerk of the court rendering the judgment, or condemning the land for sale, five thousand dollars ($5,000), to be invested under the order of the court, in the purchase of a homestead for the debtor, and only the surplus over and above five thousand dollars ($5,000) shall be applied to the payment of the execution.