Except as provided in section 41 of this title, the real property of the deceased is the property of those to whom it descends by law or is devised by will, subject to the possession of the executor or administrator, and to be applied to the satisfaction of claims against the estate, as by this chapter provided. Upon the settlement of the estate and the termination of the administration thereof so much of such real property as remains unsold or unappropriated is discharged from such possession and liability without any order therefor. But if there is any surplus of the proceeds of sale of such real property or any part thereof, the court shall order and direct a distribution of such surplus among those who would have been entitled to the land if the same had not been sold.