A federal judge has thrown out Donald Trump's $1.8bn IRS settlement, saying the case was brought for an improper purpose and referring a lawyer for possible disciplinary action.