There are two long standing bugs related to gold in the game. First, if you pause while training units, you can train more than you have gold for. Second, if you store your gold in the trading post and then transfer it to your town, you can pay raiders before the transfer is complete, and it won’t deduct the gold.