What's happening is that some other civ has beaten you to the punch and completed the Wonder ahead of you. Since there can only be one of each, once someone builds it you have to switch production to something else. It has nothing to do with your treasury, Wonders have no maintenance costs.