(1) Except as otherwise provided in subsection (2) of this section, whenever any real property subject to sale for taxes is within the corporate limits of any city, village, school district, drainage district, or irrigation district, it shall have the right and power through its governing board or body to purchase such real property for the use and benefit and in the name of the city, village, school district, drainage district, or irrigation district as the case may be. The treasurer of the city, village, school district, drainage district, or irrigation district may assign the certificate of purchase by endorsement of his or her name on the back thereof when directed so to do by written order of the governing board.
(2) No such sale shall be made to any city, village, school district, drainage district, or irrigation district by the county treasurer (a) when the real property has been previously sold to the county, but in any such case, the city, village, school district, drainage district, or irrigation district may purchase the tax certificate held by the county or (b) if a land bank has given an automatically accepted bid on such real property pursuant to section 18-3417.